Code example for FileChannel

Methods: lock

0
            fail("Passing illegal args to lock should fail.");
        } catch (IllegalArgumentException ex) {
            // expected 
        } 
        try { 
            readWriteChannel.lock(-1, 10, false);
            fail("Passing illegal args to lock should fail.");
        } catch (IllegalArgumentException ex) {
            // expected 
        } 
 
        // Lock a range at the front, shared. 
        FileLock flock1 = readWriteChannel.lock(22, 110, true);
 
        // Try to acquire an overlapping lock. 
        try { 
            readWriteChannel.lock(75, 210, true);
        } catch (OverlappingFileLockException exception) {
            // expected 
            flock1.release();
        } 
    } 
Connect your IDE to all the code out there  Get Codota for Java