public final FileLock lock () throws IOException

Acquires an exclusive lock on this channel's file.

An invocation of this method of the form fc.lock() behaves in exactly the same way as the invocation

     fc.lock(0L, Long.MAX_VALUE, false) 

Returns:  A lock object representing the newly-acquired lock

Exceptions:
ClosedChannelException     If this channel is closed
AsynchronousCloseException     If another thread closes this channel while the invoking thread is blocked in this method
FileLockInterruptionException     If the invoking thread is interrupted while blocked in this method
OverlappingFileLockException     If a lock that overlaps the requested region is already held by this Java virtual machine, or if another thread is already blocked in this method and is attempting to lock an overlapping region of the same file
NonWritableChannelException     If this channel was not opened for writing
IOException     If some other I/O error occurs

See also:
lock(long,long,boolean), tryLock(), tryLock(long,long,boolean)