File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes output newline to CSV file how to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "output newline to CSV file how to" Watch "output newline to CSV file how to" New topic
Author

output newline to CSV file how to

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 102
I would like to enter a new item into a CSV file but all my items being entered are all staying on one line in the CSV file. I would like each new item to show up on a new line and I can't seem to find the code to make it work. I've tried the \n and that didn't work.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38765
    
  23
You probably don’t need to call flush(); if you look here, you will find out why.
There are methods in the BufferedWriter class which can help with new lines. You are better off buffering your FileWriter with a BufferedWriter. There is an example in the BufferedWriter API. BufferedWriter has a write() method which writes a String, but I think you would do better to put all your Strings together with a StringBuilder, and call its toString() method. That is because you get better performance with fewer calls to access the file. Write one line at a time rather than one word at a time.
Khunga Eusuph Qolo
Greenhorn

Joined: Apr 08, 2014
Posts: 1
it works if you use it with FileWriter...It really does!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38765
    
  23
Welcome to the Ranch
 
 
subject: output newline to CSV file how to