usefilelocks.java
来自「Here is the Java files with 14 different」· Java 代码 · 共 34 行
JAVA
34 行
// $Id$import java.io.*;import java.nio.*;import java.nio.channels.*;public class UseFileLocks{ static private final int start = 10; static private final int end = 20; static public void main( String args[] ) throws Exception { // Get file channel RandomAccessFile raf = new RandomAccessFile( "usefilelocks.txt", "rw" ); FileChannel fc = raf.getChannel(); // Get lock System.out.println( "trying to get lock" ); FileLock lock = fc.lock( start, end, false ); System.out.println( "got lock!" ); // Pause System.out.println( "pausing" ); try { Thread.sleep( 3000 ); } catch( InterruptedException ie ) {} // Release lock System.out.println( "going to release lock" ); lock.release(); System.out.println( "released lock" ); raf.close(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?