[英]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.