MAC (jdk1.8.0_162)運行如下代碼會無法關(guān)閉,并且無法正常關(guān)機,只能強制關(guān)機,如果直接用idea運行,再用idea打開相應(yīng)文件,會導(dǎo)致idea掛掉,強制退出idea后,將無法再次打開。在Windows和Linux環(huán)境下運行沒有問題。
有沒有人知道這是什么原因?
File file = new File("./testfile");
try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
FileChannel fileChannel = randomAccessFile.getChannel()) {
ByteBuffer byteBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
fileChannel.position(file.length());
fileChannel.write(byteBuffer);
byteBuffer.clear();
} catch (IOException ex) {
ex.printStackTrace();
}