Help on file locking# Java - 爪哇娇娃
s*n
1 楼
Hi,
I am writing an applicaiton which may have multiple threads operating on a
single file (e.g. myfile.txt). I found an example like this:
http://javaalmanac.com/egs/java.nio/SetFileLock.html
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
try {
// Get a file channel for the file
File file = new File("myfile.txt");
FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
// Use the file channel to create a lock
I am writing an applicaiton which may have multiple threads operating on a
single file (e.g. myfile.txt). I found an example like this:
http://javaalmanac.com/egs/java.nio/SetFileLock.html
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
try {
// Get a file channel for the file
File file = new File("myfile.txt");
FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
// Use the file channel to create a lock