Code example for FileLock

Methods: release

0
 
    public void test_lockReadWrite() throws IOException {
        // Acquire an exclusive lock across the entire file. 
        FileLock flock = readWriteChannel.lock();
        if (flock != null) {
            flock.release();
        } 
    } 
 
    public void test_illegalLockParameters() throws IOException {
        // Cannot lock negative positions 
        try { 
            readOnlyChannel.lock(-1, 10, true);
            fail("Passing illegal args to lock should fail.");
        } catch (IllegalArgumentException ex) {
            // expected 
        } 
        try { 
            writeOnlyChannel.lock(-1, 10, false);
            fail("Passing illegal args to lock should fail.");