Code example for FileChannel

Methods: tryLock

0
        flock2.release();
    } 
 
    public void test_tryLock() throws IOException { 
        try { 
            readOnlyChannel.tryLock();
            fail("Acquiring a full exclusive lock on a read channel should have thrown an exception.");
        } catch (NonWritableChannelException ex) {
            // Expected. 
        } 
    } 
 
    public void test_tryLockLLZ() throws IOException { 
        // It is illegal to request an exclusive lock on a read-only channel 
        try { 
            readOnlyChannel.tryLock(0, 99, false);
            fail("Acquiring exclusive lock on read-only channel should fail");
        } catch (NonWritableChannelException ex) {
            // Expected 
        } 
Stop searching for code, let great code find you!  Add Codota to your java IDE