文件锁

RandomAccessFile raf = new RandomAccessFile(file, "rw");

FileChannel fc = raf.getChannel();

FileLock fl = fc.lock();

...

fl.release();

 

 

 

read ->

String line = "";
   while ((line = raf.readLine()) != null) {
      //do

   }

 

write ->

// append

long len = raf.length();
raf.seek(len);

raf.writeBytes("xxx");

你可能感兴趣的:(文件)