RandomAccessFile FileChannel mac上运行出错

MAC (jdk1.8.0_162)运行如下代码会无法关闭,并且无法正常关机,只能强制关机,如果直接用idea运行,再用idea打开相应文件,会导致idea挂掉,强制退出idea后,将无法再次打开。在Windows和Linux环境下运行没有问题。

有没有人知道这是什么原因?

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

你可能感兴趣的:(RandomAccessFile FileChannel mac上运行出错)