Spring batch-Delete the flatfile from directory after processed

别来无恙 提交于 2019-11-29 02:32:04

Override the FlatFileItemReader.setResource() method as

public void setResource(Resource resource) {
  this.resource = resource;
  this.delegateReader.setResource(resource);
}

and manage file deletion in FlatFileItemReader.read() when stream is totally consumed

public T read() throws Exception {
  T o = this.delegateReader.read();
  if (o == null) {
    // Perform deletion here
    deleteFile(this.resource);
  }
  return o;
}

I have achieved it by adding proceeded file name in jobcontext as list and then in my next step I execute my custom tasklet to delete file or move files based on the list.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!