Off by itself: RandomAccessFile

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Bruce Eckel’s Thinking in Java Contents | Prev | Next

RandomAccessFile

Essentially,
a
RandomAccessFile
works like a
DataInputStream
pasted together with a
DataOutputStream
and
the methods
getFilePointer( )
to find out where you are in the file,
seek( )
to move to a new point in the file, and
length( )
to determine the maximum size of the file. In addition, the constructors
require a second argument (identical to
fopen( )
in
C) indicating whether you are just randomly reading (
“r”)
or reading and writing (
“rw”).
There’s no support for write-only files, which could suggest that
RandomAccessFile
might have worked well if it were inherited from
DataInputStream.

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read