0

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

1 Answer 1

1

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
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.