views:

767

answers:

3

Is there a programatic way from java to force a file deletion on windows even if the file is locked by some process? I cannot kill the process that locks the file.

+4  A: 

you can go through JNI. But the whole point of locking was NOT to allow for deletion from another process.

So, unless you're running Windows 9x, this might be impossible to do.

That said, if you're aware of a way to do it using WIN32, then you might be able to do it in java using JNI.

anjanb
+2  A: 

I am not an expert on windows, but I do not know of a way in OR OUT of Java to reliably force the deletion of a file that is currently open to a process while the process continues to run.

mcherm
+2  A: 

Use Unlocker. Call it from Java as an external process.

Tom