美文网首页
RandomAccessFile FileChannel mac

RandomAccessFile FileChannel mac

作者: rarexixi | 来源:发表于2018-06-22 15:26 被阅读0次

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

      本文链接:https://www.haomeiwen.com/subject/hfbkyftx.html