I have a Spring Batch FlatFileItemWriter
which writes data to a specific location with a file name(let's say A.txt for example). Now I need the same file to be written with different file name (let's say B.txt) . How can I achieve this with a single item writer? Is it possible?If not are there any alternative solutions?The below is my code
public FlatFileItemWriter<MyRecord> myItemWriter(@Qualifier("myAggregator") LineAggregator<MyRecord> lineAggregator) throws IOException {
String fileName= this.localTempPath + fileProperties.myLength() + getTime();
return new FlatFileItemWriterBuilder<MyRecord>()
.name("my_itemWriter")
.resource(new FileSystemResource(//path of resource)
.lineAggregator(lineAggregator)
.encoding(fileProperties.getEncodingMyLength())
.append(true)
.lineSeparator("\r\n")
.build();
}
You can use a CompositeItemWriter that delegates to two
FlatFileItemWriter
s (one for each file).As mentioned above, it is possible, but an alternative could be adding a tasklet step that duplicates the file with a different name.