Code example for FileChannel

Methods: lock

    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 
    public void test_tryLock() throws IOException { 
        try { 
            fail("Acquiring a full exclusive lock on a read channel should have thrown an exception.");
        } catch (NonWritableChannelException ex) {
Stop searching for code, let great code find you!  Add Codota to your java IDE