简体   繁体   English

java.nio.file.FileSystemException: C:\test.csv -> C:\test2.csv: The process cannot access the file because it is being used by another process in java

[英]java.nio.file.FileSystemException: C:\test.csv -> C:\test2.csv: The process cannot access the file because it is being used by another process in java

I have spring batch, here I am retrieving the files from the folder and then reading the file using OpenCV library, code is like this.我有 spring 批处理,这里我从文件夹中检索文件,然后使用 OpenCV 库读取文件,代码是这样的。

 List<SendingFile> sendCloudFile = new CsvToBeanBuilder<SendingFile>(new FileReader(file.getAbsolutePath(), StandardCharsets.UTF_8))
                        .withType(SendingFile.class)
                        .build()
                        .parse();

After that when I try to delete the same file, then it is giving me an error.之后,当我尝试删除同一个文件时,它给了我一个错误。 (The process cannot access the file because it is being used by another process.) What I am missing here? (该进程无法访问该文件,因为它正在被另一个进程使用。)我在这里缺少什么?

@Override
    public ExitStatus afterStep(StepExecution stepExecution) {
        if (stepExecution.getExitStatus().equals(ExitStatus.FAILED)) {
            service.updateErrorStatus(mailApplicationId, null, null);
        }
        for (Map.Entry<String, String> processedFile : processedFileList.entrySet()) {
            File newFile = new File(recoveryFolder, processedFile.getKey());
            try {
                Files.move(Paths.get(processedFile.getValue()), Paths.get(recoveryFolder, processedFile.getKey()), REPLACE_EXISTING);
            } catch (Exception ex) {
                log.warn("Error in moving the file. ");
                log.warn(ex.getMessage());
            }
        }
        return stepExecution.getExitStatus();
    }

This is a known issue: https://github.com/spring-projects/spring-batch/issues/1500 .这是一个已知问题: https://github.com/spring-projects/spring-batch/issues/1500

The workaround is to use a different step to move the file instead of doing it in a listener.解决方法是使用不同的步骤来移动文件,而不是在侦听器中进行。

暂无
暂无

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

相关问题 此进程无法访问该文件,因为 KOTLIN 中的另一个进程 (java.nio.file.FileSystemException) 正在使用该文件 - This process cannot access the file because the file is being used by another process (java.nio.file.FileSystemException) in KOTLIN 如何解决 java.nio.file.FileSystemException 进程无法访问该文件,因为它正在被另一个进程使用 - How to resolve java.nio.file.FileSystemException The process cannot access the file because it is being used by another process java.nio.file.FileSystemException:进程无法访问该文件,因为它正被另一个进程使用 - java.nio.file.FileSystemException: The process cannot access the file because it is being used by another process java.nio.file.FileSystemException 进程无法访问该文件,因为它正被另一个进程使用 - java.nio.file.FileSystemException The process cannot access the file because it is being used by another process java.nio.file.FileSystemException:无法访问该文件,因为它正由另一个进程使用 - java.nio.file.FileSystemException : cannot access the file because it is being used by another process java.nio.file.FileSystemException: C:\p12\dummy.p12: 该进程无法访问该文件,因为它正被另一个进程使用 - java.nio.file.FileSystemException: C:\p12\dummy.p12: The process cannot access the file because it is being used by another process FileSystemException 进程无法访问该文件,因为它正被另一个进程使用 测试后无法正确清除结果文件 - FileSystemException The process cannot access the file because it is being used by another process Can't correctly clear result files after test java - 该进程无法访问该文件,因为它正被另一个进程使用 - java - The process cannot access the file because it is being used by another process readAllBytes()。 FileSystemException:该进程无法访问该文件,因为它正在被另一个进程使用 - readAllBytes(). FileSystemException: The process cannot access the file because it is being used by another process java.io.FileNotFoundException:该进程无法访问该文件,因为它正在被另一个进程使用) - java.io.FileNotFoundException: The process cannot access the file because it is being used by another process)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM