RandomAccessFile

While FileInputStreams are useful for reading files sequentially, RandomAccessFiles allow users to access files in a non-sequential fashion.

 

RandomAccessFile classes are instantiated using ‘r’ or ‘rw’ mode to specify read or read-write access, respectively. One of the following constructors may be used:

 

Like FileInputStream and FileOutputStream, RandomAccessFiles support the baseline read and write methods. Several methods are available to work with RandomAccessFile objects.

The getFilePointer() method returns the current location of the file pointer within a file. The seek() method sets the file pointer to a particular location within the file. The length() method returns the length of the file. As shown in the diagram, all read/write operations on Java primitive types are implemented through the DataInput and DataOutput interfaces.

Next...                                                                                                                          page 7-19