【发布时间】:2013-05-10 10:36:22
【问题描述】:
我想知道以下之间的区别:
FileChannel fc = FileChannel.open();
RandomAccessFile ra = new RandomAccessFile("RandomFile", "rw");
从 Java 7 开始,FileChannel 类实现了SeekableByteChannel,因此具有随机访问文件所需的一切。
我们可以说两者完全一样吗?
【问题讨论】:
我想知道以下之间的区别:
FileChannel fc = FileChannel.open();
RandomAccessFile ra = new RandomAccessFile("RandomFile", "rw");
从 Java 7 开始,FileChannel 类实现了SeekableByteChannel,因此具有随机访问文件所需的一切。
我们可以说两者完全一样吗?
【问题讨论】:
FileChannel 具有更多功能,因为它也是GatheringByteChannel、InterruptibleChannel、ScatteringByteChannel。此外它还可以锁定文件、传输文件、使用直接字节缓冲区,请参阅 API
【讨论】: