📄 e167. persisting changes to a memory-mapped bytebuffer.txt
字号:
Changes to a memory-mapped ByteBuffer are not necessarily sent immediately to the underlying storage device. In some applications, such as with a memory-mapped register, the change should be sent immediately. The MappedByteBuffer.force() method is used to force all changes to the underlying storage device immediately.
try {
// Create a ByteBuffer on a memory-mapped file
File file = new File("filename");
FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_WRITE, 0, (int)channel.size());
// Make a change to the ByteBuffer
buf.put(0, (byte)0xFF);
// Force the change to the file system
buf.force();
// Close the file
channel.close();
} catch (IOException e) {
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -