获得文件锁

来源:互联网 发布:v2视频软件下载 编辑:程序博客网 时间:2024/04/30 13:03
//: c12:FileLocking.java// {Clean: file.txt}import java.io.FileOutputStream;import java.nio.channels.*;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();  }} ///:~
原创粉丝点击