<<< FileChannel example: accessing a random access file randomly | Index | RandomAccessFile vs. FileChannel vs. BufferedReader >>> |
Class java.io.RandomAccessFile provides random access to a file for reading and/or writing
Constructors of the RandomAccessFile class:
Constructor Throws ---------------------------------- ---------------------- RandomAccessFile(File, stringMode) FileNotFoundException RandomAccessFile(stringPathName, stringMode) FileNotFoundException
Access mode values:
"r" -- Open for reading only
"rw" -- Open for reading and writing. If the file doesn't already exist, an attempt will be made to create it
"rws" -- Open for reading and writing. Updates to file content or metadata written synchronously to storage device
"rwd" -- Open for reading and writing. Updates to file content written synchronously to the storage device
Notes:
The "rwd" mode forces writes to be synchronous with the physical media, which can be a very slow mode.
Latest RandomAccessFile implementation uses the NIO ( Java New IO ) classes in its implementation -- FileChannel and FileDescriptor.
<<< FileChannel example: accessing a random access file randomly | Index | RandomAccessFile vs. FileChannel vs. BufferedReader >>> |