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?
Asked
Active
Viewed 1,014 times
0
-
Unless you tell the problems you have faces in doing. It is difficult to answer. – Ramesh PVK Jun 04 '12 at 05:25
2 Answers
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