经典java书籍《thinking in java(第三版)》的源码

源代码在线查看: filelocking.java

软件大小: 178 K
上传用户: liu2237329
关键词: java thinking in 书籍
下载地址: 免注册下载 普通下载 VIP

相关代码

				//: 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.*;
				
				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();
				  }
				} ///:~			

相关资源