D
David Zimmerman
If you locked the file without specifying a region, it usesVX said:I have a question about the new FileLock functionality in java.nio packages.
I wrote a little test code like this
FileInputStream f=new FileInputStream("xyz.txt");
FileChannel fc=f.getChannel();
System.out.println("The size of the file is: " + fc.size() );
//now the file lock
FileLock lock=fc.lock(); //***this is suppose to lock the entire file
System.out.println("The size of the lock is: " + lock.size());
Now here is the the problem. the size given by FileChannel is about 306
bytes (which is ok). ***But the size give by the lock is 9007199254740991
bytes!!!
I also checked the API docs...here is what it says
size
public final long size()Returns the size of the locked region in bytes.
A locked region need not be contained within, or even overlap, the actual
underlying file, so the value returned by this method may exceed the file's
current size.
Returns:
The size of the locked region
Here are my questions:
1: Does this means that my lock has locked a region of 9007199254740991
bytes. What will happen to any other file saved in that region?
2:What is this locked region if it doesnt 'contained within or even overlap
with the actual underlying file' ?
3: why should the lock size exceed the current file size. What is the
advantage of having this flexibility?
Thanks in advance
Long.MAX_VALUE to represent the entire file. See the doc for
FileChannel.lock() (as opposed to lock(long position,long size, boolean
shared))