Wie kann ich MappedByteBuffer richtig schließen?

Dies ist der Code, den ich ausführe:

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");
    }
}

Bevor ich eine Taste drücke, versuche ich, die Datei in FAR Manager manuell zu löschen. Aber FAR sagt, dass die Datei gesperrt ist:

 The process cannot access the file because it is being used by another process.
                     Cannot delete the file
                         D:\temp\file
                    Object is being opened in:
 Java(TM) Platform SE binary (PID: 5768, C:\Program Files\Java\jdk1.8.0_05\bin\javaw.exe)

Erst nach dem Drücken einer Taste wird die Anwendung beendet und ich kann die Datei löschen.

Was ist los mit meinem Code?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage