Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.nio.file.FileSystemException:C:\test.csv->;C:\test2.csv:进程无法访问该文件,因为java中的另一个进程正在使用该文件_Java_Spring Boot_Spring Batch - Fatal编程技术网

java.nio.file.FileSystemException:C:\test.csv->;C:\test2.csv:进程无法访问该文件,因为java中的另一个进程正在使用该文件

java.nio.file.FileSystemException:C:\test.csv->;C:\test2.csv:进程无法访问该文件,因为java中的另一个进程正在使用该文件,java,spring-boot,spring-batch,Java,Spring Boot,Spring Batch,我有SpringBatch,在这里我从文件夹中检索文件,然后使用OpenCV库读取文件,代码如下 List<SendingFile> sendCloudFile = new CsvToBeanBuilder<SendingFile>(new FileReader(file.getAbsolutePath(), StandardCharsets.UTF_8)) .withType(SendingFile.class)

我有SpringBatch,在这里我从文件夹中检索文件,然后使用OpenCV库读取文件,代码如下

 List<SendingFile> sendCloudFile = new CsvToBeanBuilder<SendingFile>(new FileReader(file.getAbsolutePath(), StandardCharsets.UTF_8))
                        .withType(SendingFile.class)
                        .build()
                        .parse();
List sendCloudFile=new CsvToBeanBuilder(新文件读取器(file.getAbsolutePath(),StandardCharsets.UTF_8))
.withType(SendingFile.class)
.build()
.parse();
之后,当我试图删除同一个文件时,它会给我一个错误。(该进程无法访问该文件,因为其他进程正在使用该文件。) 我错过了什么

@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();
    }
@覆盖
公共出口状态后步骤(步骤执行步骤执行){
if(stepExecution.getExitStatus().equals(ExitStatus.FAILED)){
service.updateErrorStatus(mailApplicationId,null,null);
}
对于(Map.Entry processedFile:processedFileList.entrySet()){
File newFile=新文件(recoveryFolder,processedFile.getKey());
试一试{
Files.move(path.get(processedFile.getValue()),path.get(recoveryFolder,processedFile.getKey()),替换现有的文件);
}捕获(例外情况除外){
log.warn(“移动文件时出错”);
log.warn(例如getMessage());
}
}
返回stepExecution.getExitStatus();
}
这是一个已知问题:

解决方法是使用不同的步骤移动文件,而不是在侦听器中执行