This code is able to write data to csv file but the only problem is the data is getting written in single column only.
I want the data to come in different column. I am new to bean io and not able to figure it out.
I have tried below given code and not able get output in proper format:
public class XlsWriter {
public static void main(String[] args) throws Exception {
StreamFactory factory = StreamFactory.newInstance();
factory.load("C:\\Users\\PV5057094\\Demo_workspace\\XlsxMapper\\src\\main\\resources\\Employee.xml");
Field[] fields = Employee.class.getDeclaredFields();
System.out.println("fileds" + fields.length);
List<Object> list = new ArrayList<Object>();
for (Field field : fields) {
list.add(field.getName());
}
BeanReader in = factory.createReader("EmployeeInfo", new File("C:\\Temp\\Soc\\textInput.txt"));
BeanWriter out = factory.createWriter("EmployeeInfo", new File("C:\\Temp\\Soc\\output.csv"));
Object record;
while ((record = in.read()) != null) {
System.out.println(record.toString().length());
out.write(record);
System.out.println("Record Written:" + record.toString());
}
in.close();
out.flush();
out.close();
}
}
textInput.txt
AAAAABBBBBCCCCC
AAAAABBBBBCCCCC
AAAAABBBBBCCCCC
AAAAABBBBBCCCCC
AAAAABBBBBCCCCC
<?xml version="1.0" encoding="UTF-8"?>
<beanio xmlns="http://www.beanio.org/2012/03"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">
<stream name="EmployeeInfo" format="fixedlength">
<record name="employee"
class="com.aexp.gmnt.imc.record.submission.Employee" minOccurs="0"
maxOccurs="unbounded" order="1">
<field name="firstName" length="5" padding="0" justify="right" />
<field name="lastName" length="5" padding="0" justify="right"/>
<field name="title" length="5" padding="0" justify="right"/>
</record>
</stream>
I want every record value in different column of a CSV file, but currently it is comming in a single column only, please help.