你想要一个FileLock:
FileChannel channel = new RandomAccessFile("C:\foo", "rw").getChannel();// Try acquiring the lock without blocking. This method returns// null or throws an exception if the file is already locked.FileLock lock = channel.tryLock();// ...// release itlock.release();
为了简单起见,我省略了一个try / finally块,但您不应该在生产代码中使用
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)