문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top