The RandomAccessFile class offers all the functionality of DataInputStream and DataOutputStream combined, plus additional capabilities.
|
To open a random access file for reading, use:
-
RandomAccessFile in =
-
new RandomAccessFile( filename, "r" );
-
Such a file may be accessed sequentially with
-
in.readLine();
-
or randomly by repositioning the file pointer:
-
in.seek( offset );
-
where offset is a byte offset into the random file. (Use "rw" for read/write access.)
|
Random access files have no inherent structure; the structure must be imposed by the programmer.
|