简体   繁体   English

删除 java 中的文件时出现 java.nio.file.NoSuchFileException

[英]java.nio.file.NoSuchFileException while deleting the file in java

while deleting the file i am getting java.nio.file.NoSuchFileException below is my code sinippet.The issue her is it is getting called multiple time the same file which got deleted.在删除文件时,我得到 java.nio.file.NoSuchFileException 下面是我的代码 sinippet。她的问题是它被多次调用同一个文件被删除。

public static synchronized void deleteFiles(File[] files) {
    for (File file : files) {
        if (file.isDirectory()) {
            deleteFiles(Objects.requireNonNull(file.listFiles())); // Calls same method again.
        } else if(file.getAbsoluteFile().exists()) {
            System.out.println("SJ================ before deleting");
            file.delete();
        }
    }   
}

Here's the stacktrace这是堆栈跟踪

 java.nio.file.NoSuchFileException: /home/ruchitha/Documents/Project_Banyan/DynamicCAError/D:/Project/Project_Banyan/Dynamic_error_files/cpr/ottcConfig/IS20/OTTC/ottc_BWA_eng.properties
     at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
     at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
     at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)

The file you passed into that function really can not exist, as it contains invalid characters:您传递给 function 的文件确实不存在,因为它包含无效字符:
..._Banyan/DynamicCAError/D:/Project/Project
Problem can be found here: ^问题可以在这里找到:^

Colons are not allowed in directory- and filenames.目录名和文件名中不允许使用冒号。 Make sure you pass correct files into your function.确保将正确的文件传递到 function。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM