文件锁
2008-01-05 08:58:16 来源:WEB开发网核心提示:// : c12:FileLocking.java// {Clean: file.txt}// From 'Thinking in Java, 3rd ed.' (c) BrUCe Eckel 2002// www.BruceEckel.com. See copyright notice in Copy
// : c12:FileLocking.java
// {Clean: file.txt}
// From 'Thinking in Java, 3rd ed.' (c) BrUCe Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
import java.io.FileOutputStream;
import java.nio.channels.FileLock;
public class FileLocking {
public static void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("file.txt");
FileLock fl = fos.getChannel().tryLock();
if (fl != null) {
System.out.PRintln("Locked File");
Thread.sleep(100);
fl.release();
System.out.println("Released Lock");
}
fos.close();
}
} ///:~
更多精彩
赞助商链接