Issue
I have to add one Disclaimer Line in a CSV file before the headers using Spring Batch implementation. For example, below is my expected CSV File:
Disclaimer-XYZ... Col1 Col2 Col3 abc efg pqr
Currently, I am using FlatFileItemWriter and FlatFileHeaderCallBack to create the CSV File along with writing headers and their corresponding values in it.
But I am not able to add a disclaimer and then follow by the Headers as shown above.
Here is a glimpse of my code:
stepWriter.setHeaderCallback(new FlatFileHeaderCallback()
public void writeHeader(Writer writer) throws IOException{`
writer.write(disclaimer);
writer.write(“Col1”, “Col2”,”Col3”);
}
});
But with the above code the actual CSV looks like this:
Disclaimer-XYZ Col1 Col2 Col3
Solution
According to your description, Disclaimer-XYZ
is part of the header to me, so I would keep it simple and update your header callback to something like:
stepWriter.setHeaderCallback(new FlatFileHeaderCallback() {
@Override
public void writeHeader(Writer writer) throws IOException {
writer.write("Disclaimer-XYZ");
writer.write(System.lineSeparator());
writer.write("Col1 Col2 Col3");
}
})
This should print:
Disclaimer-XYZ
Col1 Col2 Col3
...
Answered By - Mahmoud Ben Hassine