Dónal
Dónal

Reputation: 187499

detect locked file

Given a reference to a File instance, is it possible to (programatically) detect whether the corresponding file is locked, and if so, which process is holding the lock?

I'm using Java 5, running on Windows.

Thanks, Don

Upvotes: 4

Views: 1869

Answers (1)

christian
christian

Reputation: 401

I think this is only possible in a native way. You need to access FileHandle informations. Write a Dll and connect it to your java app via JNI. Call NtQuerySystemInformation with SystemHandleInformation(16). You get a list with all open Handles, search for FileHandles, compare FileHandles with your own File.

Upvotes: 2

Related Questions