I am new to Spring Batch. I have a simple setup that uses FlatFileItemReader to read in a file and then uses a writer to write it to a database. I would like to delete the file after it is read (or after the writer, doesn't matter). What is the best/simplest way to do this?
First. When posting code or configuration. Please use the CODE tags to keep it formatting with tab to be readable. I can't read your configuration as posted.
On to your issue. You can't delete in read, because Spring Batch does chunk processing. It reads one item at a time, then passes a collection of the items to the writer. So if you have a chunk size of 10 and 100 lines in the file. It will read one line at a time, after it reads and processes 10 lines it passes the 10 lines to the writer, then the transaction is committed. Then it reads the next line and process, repeating that 10 times, then calls the writer with the collection of those 10 lines, all lines have been read and processes. That would be done in a step. So the Step is assigned to the Job. You can make a second Step in the Job, which the second step is the delete the file.
JavaRanch requires all users to use their real first and real last names as their user/display name. Your does not meet this requirement. Please click the My Profile link above and change your display name.