Jdk 7中的FileChannel.open()与RandomAccessFile有何区别?

3

我想了解以下内容的区别:

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

自Java 7以来,类FileChannel实现了SeekableByteChannel,因此具有随机访问文件所需的所有功能。
我们可以说这两者完全相同吗?
1个回答

1

FileChannel 有更多的功能,因为它也是 GatheringByteChannelInterruptibleChannelScatteringByteChannel。此外,它还可以锁定文件、传输文件、使用直接字节缓冲区,详见 API。


那么我们可以说,RandomAccessFile 已经被 FileChannel 完全取代了(现在实现了 SeekableByteChannel)? - Rollerball

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接