我已经尝试删除@afterJob上的文件,并且在主要步骤之后执行第二步,但是没有成功。任何想法。
java.nio.file.FileSystemException: pathtofile/filename: The process cannot access the file because it is being used by another process
。
.listener(completionListener)
.start(transactionCsvFileToConsoleWriteStep)
.next(deleteFileStep())
.build();
@Bean
public Step deleteFileStep() {
return stepBuilderFactory.get("deleteFileStep")
.tasklet(fileDeletingTasklet())
.build();
}
@Bean
public FileDeletingTasklet fileDeletingTasklet() {
FileDeletingTasklet tasklet = new FileDeletingTasklet();
tasklet.setDirectory(inputResources);
return tasklet;
}
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
File[] files = directory.getFile().listFiles();
for (File file : files) {
boolean deleted = file.delete();
if (!deleted) {
throw new UnexpectedJobExecutionException("Could not delete