parchambeau
parchambeau

Reputation: 1141

BeanIO Writing two streams to the same file

I am trying to figure out the best way in which I can write two streams to the same file. The issue that I am trying to solve for is that the top of my file has an XML Header, and then at the bottom I need a comma delimited set of information to be appended.

Is there an easy way to do this in BeanIO? I have already created the xml header but attempting to use the following code block is executing but doing nothing:

BeanWriter xmlHeaderWrite = factory.createWriter(
                          "SendBulkEmailRequest",new   File("xmltest.csv"));
BeanWriter delimRecordsWrite = factory.createWriter(
                          "PipeDelimRecords",new File("xmltest.csv"));
// write an object directly to the BeanWriter
xmlHeaderWrite.write(requestHeader);
delimRecordsWrite.write(customer);

Upvotes: 0

Views: 1224

Answers (1)

Kevin
Kevin

Reputation: 76

Rather than passing two File references, you can open a single FileWriter and pass it to both createWriter() calls. Then don't forget to flush and close it yourself.

Upvotes: 2

Related Questions