0

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?

Jonas
  • 121,568
  • 97
  • 310
  • 388
gnreddy
  • 2,393
  • 4
  • 22
  • 18

2 Answers2

2

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

UVM
  • 9,776
  • 6
  • 41
  • 66
0

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.

user207421
  • 305,947
  • 44
  • 307
  • 483