从Java强制在Windows上删除文件

时间:2022-11-22 20:20:31

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.

是否有一种编程方式从java强制在Windows上删除文件,即使该文件被某些进程锁定?我无法杀死锁定文件的进程。

3 个解决方案

#1


6  

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

你可以通过JNI。但锁定的全部意义并不是允许从另一个进程中删除。

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

因此,除非您运行Windows 9x,否则可能无法执行此操作。

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.

也就是说,如果你知道使用WIN32的方法,那么你可以使用JNI在java中完成它。

#2


3  

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.

我不是Windows的专家,但我不知道在OR OUT中的一种方法是在进程继续运行时可靠地强制删除当前对进程开放的文件。

#3


2  

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

使用解锁器。从Java中将其称为外部进程。

#1


6  

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

你可以通过JNI。但锁定的全部意义并不是允许从另一个进程中删除。

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

因此,除非您运行Windows 9x,否则可能无法执行此操作。

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.

也就是说,如果你知道使用WIN32的方法,那么你可以使用JNI在java中完成它。

#2


3  

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.

我不是Windows的专家,但我不知道在OR OUT中的一种方法是在进程继续运行时可靠地强制删除当前对进程开放的文件。

#3


2  

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

使用解锁器。从Java中将其称为外部进程。