Here you can find the source of isLocked(File file)
public static boolean isLocked(File file)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.nio.file.StandardOpenOption; public class Main { public static boolean isLocked(File file) { if (!file.isFile()) { return false; }//from ww w . j a va 2 s . co m try (FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE)) { FileLock lock = fc.tryLock(); if (lock != null) { lock.release(); return false; } else { return true; } } catch (IOException e) { return true; } } }