FileLock以防止删除文件,但我无法打开它

时间:2018-05-13 12:47:35

标签: java filelock

我正在使用FileLock来阻止删除.zip文件但我无法打开它。所以我试图找到阻止文件但能够打开它的东西。 有我的代码:

File file = new File(myfile);

FileInputStream in = new FileInputStream(file);
FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
FileLock lock = channel.lock();

try {
    lock = channel.tryLock();
} catch (OverlappingFileLockException e) {}

谢谢!

1 个答案:

答案 0 :(得分:0)

OH no ok Channels.newChannel(in)完美无缺