如何判断哪些进程在Windows中使用Java下的文件? [英] How can I tell what processes are using a file under Java in Windows?
问题描述
我们有一个用Java编写的计划任务在Windows平台上失败,因为有时它需要删除的文件仍在使用中。有没有办法在Java中我可以看到哪些进程正在使用文件并获取有关它们的信息?
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?
我想我会补充说我愿意使用JNA或JNI,如果有必要的话,我认为它会是。
I thought I would add that I am willing to use JNA or JNI if necessary, and I assume it is going to be.
推荐答案
我在Github上为JNA项目问了一个类似的问题并且 @matthiasblaesing 编写了一个代码来完成此任务。
I asked a similar question on Github for the JNA project and @matthiasblaesing wrote a code to accomplish this.
代码是 here 。
打印包含以下格式的所有正在运行的进程的列表:< exe>:< type>:< path>
。
It prints a list with all the running processes in the format: <exe>: <type>: <path>
.
这篇关于如何判断哪些进程在Windows中使用Java下的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!