2

I am writing bean file values to a CSV file using BeanIO.jar. I am not getting any error but the contents are not written to CSV File.

Please find my code and help me

  public class CSVStreamWriter {

   public void splitandWrite(List<Orders> orderList) {
        StreamFactory factory = StreamFactory.newInstance();
        factory.load("mapping.xml");
        BeanWriter writer = factory.createWriter("orders", new File(
                "C:\\sales.csv"));
        Orders orders = new Orders();
        orders.setCustomerId("1");
        orders.setCustomerName("krish");
        orders.setPackages("5");
        orders.setPackageType("units");
        orders.setProductName("oreo");
        orders.setQuantity("100");

        writer.write(orders);

    }
}

My mapping file

<?xml version="1.0" encoding="UTF-8"?>
<beanio xmlns="http://www.beanio.org/2012/03">
    <stream name="orders" format="csv">
        <record name="orders" class="com.tedge.mc.Orders">
            <field name="customerId" />
            <field name="customerName" />
            <field name="quantity" />
            <field name="productName" />
            <field name="packages" />
            <field name="packageType" />
        </record>
    </stream>
</beanio>

1 Answer 1

2

Because you don't close nor flush the BeanWriter, the content you wrote is not flushed into the file.

You should close your writer (that will do the flush):

writer.write(orders);
writer.close();
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.