📄 filelockexp.java
字号:
/**
* @(#)FileLockExp.java
*
*
* @author
* @version 1.00 2007/11/19
*/
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class FileLockExp {
/**
* Creates a new instance of <code>FileLockExp</code>.
*/
public FileLockExp() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int b;
byte tom[]=new byte[12];
try {
RandomAccessFile input=new RandomAccessFile("4.txt","rw");
FileChannel channel=input.getChannel();
while ((b=input.read(tom,0,10))!=-1) {
FileLock lock=channel.tryLock();
String s=new String(tom,0,b);
System.out.println(s);
try {
Thread.sleep(1000);
lock.release();
}
catch (Exception ee) {
System.out.println(ee);
}
}
}
catch (Exception e) {
System.out.println(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -