These are actually three questions about how to work with memory mapped files. What I did works, but I'm missing an authoritative answer.
I obtain my ByteBuffer
like follows:
raf = new RandomAccessFile(file, isReadonly ? "r" : "rw");
channel = raf.getChannel();
buffer = channel.map(mode, 0, channel.size());
For resizing, the following seems to work
raf.setLength(newLength);
channel = raf.getChannel();
without calling raf.getChannel()
, but is it really correct?
According to the Javadoc, calling force
should flush it (I'm using a local drive). I just wonder how it comes that it declares no IOException
and what happens if it fails?
What do I have to close? The RandomAccessFile
, the FileChannel
, or both of them? Do I have to call some flush
or MappedByteBuffer.force
before?