Topic: 请教filelock问题?

  Print this page

1.请教filelock问题? Copy to clipboard
Posted by: flyingdd
Posted on: 2004-11-16 20:51

小弟写的一个测试文件锁的程序,运行返回错误如下:
Exception in thread "main" java.nio.channels.NonWritableChannelException
at sun.nio.ch.FileChannelImpl.lock(Unknown Source)
at java.nio.channels.FileChannel.lock(Unknown Source)
at Lock.main(Lock.java:9)
我用win2003,是不是无法使用lock?

源代码如下:
public class Lock {
public static void main(String[] a) throws Exception {
FileInputStream fis = new FileInputStream("dogs.txt");
FileChannel fc = fis.getChannel();
while(true) {
FileLock mylock=fc.tryLock(); //应该是这句出错1
if(mylock!=null) {
System.out.println("got lock");
Thread.sleep(2000);
mylock.release();
}
Thread.sleep(333);


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923