Code example for FileChannel

Methods: lock

0
        } 
    } 
 
    public void test_lockLLZ() throws IOException { 
        // Lock a range at the front, non-shared. 
        FileLock flock1 = readWriteChannel.lock(0, 10, false);
 
        // Lock a shared range further in the same file. 
        FileLock flock2 = readWriteChannel.lock(22, 100, true);
 
        // The spec allows the impl to refuse shared locks 
        flock1.release();
        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) {