删除带有NIO文件的文件时出现Java文件系统异常。delete()

删除带有NIO文件的文件时出现Java文件系统异常。delete(),java,spring-batch,spring-integration,nio,Java,Spring Batch,Spring Integration,Nio,我得到了以下例外 java.nio.file.FileSystemException: C:\Users\abcd.zip: The process cannot access the file because it is being used by another process. at sun.nio.fs.WindowsException.translateToIOException(Unknown Source) ~[na:1.7.0_75] at sun.nio.fs

我得到了以下例外

java.nio.file.FileSystemException: C:\Users\abcd.zip: The process cannot access the file because it is being used by another process.

    at sun.nio.fs.WindowsException.translateToIOException(Unknown Source) ~[na:1.7.0_75]
    at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source) ~[na:1.7.0_75]
    at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source) ~[na:1.7.0_75]
    at sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source) ~[na:1.7.0_75]
    at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(Unknown Source) ~[na:1.7.0_75]
    at java.nio.file.Files.deleteIfExists(Unknown Source) ~[na:1.7.0_75]

我知道此文件当前已由另一个进程打开,但如何确定哪个进程已锁定此文件?我在SpringIntegration和SpringBatch中使用了这段代码,一旦文件从ftp服务器下载,它就会被传递到transformer,以将SpringIntegration消息转换为作业启动请求

很抱歉,这不是一个编码问题,因为您需要使用一个能够列出所有进程和相关文件锁的操作系统工具。AFAK无法直接从Java本身内部执行此操作(您需要运行命令行程序或挂接到本机代码中)。如果您确实希望通过Java执行此操作,则需要使用本机代码或调用本机Windows API。如果你真的想这样做,可能会帮助你开始。