FileInputStream and RandomAccessFile

K

kelvSYC

What's the difference between FileInputStream's read(), read(byte[]),
and read(byte[], int, int) methods, and the RandomAccessFile's
readByte(), readFully(byte[]) and readFully(byte[], int, int) methods,
besides the fact that one throws an EOFException and one does not?

When reading files sequentially, is there a preference for one class
over the other?
 
M

Michael Borgwardt

kelvSYC said:
What's the difference between FileInputStream's read(), read(byte[]),
and read(byte[], int, int) methods, and the RandomAccessFile's
readByte(), readFully(byte[]) and readFully(byte[], int, int) methods,
besides the fact that one throws an EOFException and one does not?

Read the API docs for the methods carefully, and you will see that
the array methods differ considerably in their behaviour.
When reading files sequentially, is there a preference for one class
over the other?

I'd say that in that case, RandomAccessFile does a lot more than you need,
which might cause complications, so you should use FileInputStream
(or DataInputStream, if you need stuff like readInt()) instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top