Java FileLock lockFile(File file, RandomAccessFile raf)

Here you can find the source of lockFile(File file, RandomAccessFile raf)

Description

lock File

License

Open Source License

Declaration

public static FileLock lockFile(File file, RandomAccessFile raf)
            throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

import java.nio.channels.*;

public class Main {
    public static FileLock lockFile(File file, RandomAccessFile raf)
            throws IOException {
        FileLock fl = null;//from   ww  w .  ja v a 2 s  . c o  m
        FileChannel fc = raf.getChannel();
        if (fc != null) {
            try {
                fl = fc.tryLock();
            } catch (OverlappingFileLockException ex) {
                throw new IOException(
                        file.getPath()
                                + ":\nDatei ist gesperrt.\n"
                                + "Bitte schlie\u00DFen Sie die Datei in dem Programm,\n"
                                + "in dem sie ge\u00F6ffnet ist.");
            } catch (IOException ex) {
                throw new IOException(file.getPath()
                        + ":\nDatei kann nicht gesperrt werden.");
            }
        }
        return fl;
    }
}

Related

  1. isFileLocked(File file)
  2. isLocked(File file)
  3. isLocked(File file)
  4. lock(File file)
  5. lockFile(File file)
  6. lockFileExists(File file)
  7. openTcpSocket(boolean blocking)
  8. pauseForLock(File f, int frequency, int totalTime)
  9. releaseQuietly(FileLock lock)