We have a scheduled task written in Java that is failing on Windows platforms because sometimes the files it needs to delete are still in use. Is there a way from within Java that I can see what processes are using a file and get information on them?
I thought I would add that I am willing to use JNA or JNI if necessary, and I assume it is going to be.
I asked a similar question on Github for the JNA project and @matthiasblaesing wrote a code to accomplish this.
The code is here.
It prints a list with all the running processes in the format: <exe>: <type>: <path>
.
One dirty way to do it is to run your application with administrative privileges and invoke a command utility such as Handle using a ProcessBuilder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With