public final FileLock tryLock () throws IOException

Attempts to acquire an exclusive lock on this channel's file.

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

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

Returns:  A lock object representing the newly-acquired lock, or null if the lock could not be acquired because another program holds an overlapping lock

ClosedChannelException     If this channel is closed
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
IOException     If some other I/O error occurs

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