Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

output newline to CSV file how to

 
Dustin Schreader
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51453
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it works if you use it with FileWriter...It really does!
 
Campbell Ritchie
Sheriff
Posts: 51453
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic