Here you can find the source of isLocked(File file)
public static boolean isLocked(File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; public class Main { public static boolean isLocked(File file) throws IOException { if (!file.isFile()) { return false; }//www .jav a2 s.c om try { RandomAccessFile raf = new RandomAccessFile(file, "rw"); try { FileChannel channel = raf.getChannel(); FileLock lock = channel.tryLock(); if (lock == null) { return true; } lock.release(); return false; } finally { raf.close(); } } catch (FileNotFoundException e) { return true; } } }