Reputation: 2503
I am new to Java NIO. I am seeing that a FileChannel
object has both read and write methods. But I am unable to read and write using the same FileChannel
at a single point of time. Is there a way to do so?
Upvotes: 0
Views: 1224
Reputation: 9914
Get a FileChannel
from RandomAccessFile object with "rw" mode.
RandomAccessFile aFile = new RandomAccessFile("abc.txt", "rw");
FileChannel inChannel = aFile.getChannel();
You can refer this link for more. FileChannel tutorial
Upvotes: 2
Reputation: 310850
If you obtain the FileChannel
from a RandomAccessFile
opened in "rw" mode you can both read and write. In all other cases you can't.
Upvotes: 0