aspose 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
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 32604
    
    4
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: output newline to CSV file how to
 
Similar Threads
null pointer
check equality of array string and string
problems creating a new larger array with one extra element
Nested for loops to the point of confusion
sorting an array from csv file.