Is there a way to read and write using the same FileChannel?
-
12-06-2021 - |
문제
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.
제휴하지 않습니다 StackOverflow