2013-05-10 41 views
2

我想知道下面的區別:FileChannel.open()VS RandomAccessFile的JDK 7中

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

由於Java 7類FileChannel工具SeekableByteChannel因此具有一切以隨機訪問的需要文件。

我們可以說2是完全一樣的嗎?

回答

1

FileChannel有更多的功能,因爲它也是GatheringByteChannel,InterruptibleChannel,ScatteringByteChannel。此外,它可以鎖定文件,傳輸文件,使用直接字節緩衝區,請參閱API

+0

所以我們可以說RandomAccessFile已經被FileChannel(現在實現了SeekableByteChannel)完全克服了嗎? – Rollerball 2013-05-10 10:47:00

+0

我會說是的 – 2013-05-10 10:47:45