// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.nio.channels.FileLock;
import java.io.FileOutputStream;
import java.io.IOException;

public class LockTest {
    public static boolean fileready(String fnm) {
        try {
            FileLock lck = (new FileOutputStream(fnm, true)).getChannel().tryLock();
            return (lck != null);
        } catch (IOException ex) {
            return false;
        }
    }
    private static void test(String fnm) {
        System.out.println(fnm + " : " + fileready(fnm));
    }
    public static void main(String[] args) {
        test("C:\\jdk131def.bat");
        test("C:\\pagefile.sys");
        test("C:\\zzz.zzz");
    }
}
