I have a spring batch that will read the CSV file, then process and write it to another CSV file. I want to write the results into two different flat files based on the process result. Need to write successfully processed records in one file and failure records in another file.
I saw few examples to use "CompositeItemWriter" but there's no exact example for multiple "FlatfileItemWriters".
Anyone, please share the example for my use case?
CompositeItemWriter
is used when valid items should be written to two or more outputs. In your case, aSkipListener
is more appropriate and can be used to write invalid items to a different file. Here is a quick example:This example skips items 3 and 7 and produces two files:
output.txt
with valid items andskipped.txt
with invalid items.