Announcement Announcement Module
Collapse
No announcement yet.
how can i delete the file that i reader-process-writer? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how can i delete the file that i reader-process-writer?

    I user the batch to process every line of file,but i cann't get the filename of the line by use org.springframework.batch.item.file.FlatFileItemRe ader ,so i write the flatFileItemReader by myself.like this:
    return lineMapper.mapLine(resource.getFile().getAbsoluteP ath()+sign+resource.getFilename()+sign+lineSize.si ze()+sign+lineCount+sign+line, lineCount);
    I need the absolutepath,filename,the total number of the file and the current line number.so i changed like that.
    it works.i can get the absolutepath,filename,the total number of the file and the current line number at the writer.
    i want delete the file at the writer listeners when the lineSize.size==lineCount .using File file = new File(m.getFilepath()); file.delete().but it return false,i can't delete. how can i delete the file? thanks.

  • #2
    A couple things to note:
    1. We just added a ResourceAware interface and the MultiResourceItemReader to populate the resource when reading from multiple places so that should handle your ability to get the file name (you can get that code in the latest snapshot).
    2. You probably cannot delete the file because the ItemReader or ItemWriter still has it open. You may need to use a StepListener so that the files can be cleaned up once the handle on the file is complete.

    Without writing some form of custom ItemReader that lets go of the file, I don't think you'll be able to delete the file mid step like you are proposing though. Is there an issue with waiting until the end?

    Comment


    • #3
      i write a new reader.and add the filename ,number of line and the totals line number to every line of the file.thank you very much.

      Comment

      Working...
      X