• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not all content of ArrayList is written to the TextFile

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

When i am trying to write ArrayList to TextFile , only half of the content of the ArrayList is being written to the File .
Where as all the content of the ArrayList is being properly printed when i use system.out.println(list.get(i))



I am struck up .pLease help

Thanks in advance.
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avoid using "\n" to write new lines in a file as this won't work for all OS's. Regardless, you may be having problems from not flushing or closing the FileWriter, but with the small bit of code posted, I don't know for sure.

Myself, I'd wrap that FileWriter in a PrintWriter object, one that I've turned auto-line flushing on (check out its constructors in the API) and then do a println for each line I wish to write. You may wish to give this a try. Your mileage may vary. Luck!
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response , but my requirement is that i need to write data from the ArrayList into a new line in a Text File .

Need help on this .
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:Thanks for the response , but my requirement is that i need to write data from the ArrayList into a new line in a Text File .


I understand, and if you re-read my post, you'll see that I have already told you how to do this. Why not give it a try first and then come back with your code attempt if it doesn't work.
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cross-post: forums.sun.com thread

Please read the forum FAQ's, including the one regarding cross-posts: BeForthrightWhenCrossPostingToOtherSites
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic