简体   繁体   中英

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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM