public static FileLock lock_file(String path) throws IOException, FileNotFoundException { RandomAccessFile file = new RandomAccessFile(path, "rw"); FileChannel fileChannel = file.getChannel(); return fileChannel.tryLock(); }