How to properly close MappedByteBuffer?
This is the code I'm running: import java.io.RandomAccessFile; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; public class Main { public static void main(String[] args) throws Exception { String filePath = "D:/temp/file"; RandomAccessFile file = new RandomAccessFile(filePath, "rw"); try { MappedByteBuffer buffer = file.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, 128); // Do something buffer.putInt(4); } finally { file.close(); System.out.println("File closed"); } System.out.println("Press any key..."); System.in.read(); System.out.println("Finished"); } }