Rollerball
Rollerball

Reputation: 13108

FileChannel.open() vs RandomAccessFile in Jdk 7

I would like to know the difference between the following:

FileChannel fc = FileChannel.open();
RandomAccessFile ra = new RandomAccessFile("RandomFile", "rw");

Since Java 7 the class FileChannel implements SeekableByteChannel therefore has all it needs in order to randomly access the file.

Can we say that the 2 are totally the same?

Upvotes: 3

Views: 1009

Answers (1)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 135992

FileChannel has many more features since it is also GatheringByteChannel, InterruptibleChannel, ScatteringByteChannel. Besides it can lock files, transfer files, work with direct byte buffers, see API

Upvotes: 1

Related Questions