aspose file tools*
The moose likes I/O and Streams and the fly likes Not all content of ArrayList is written to the TextFile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Not all content of ArrayList is written to the TextFile " Watch "Not all content of ArrayList is written to the TextFile " New topic
Author

Not all content of ArrayList is written to the TextFile

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

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.


Save India From Corruption - Anna Hazare.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Apr 18, 2009
Posts: 2234

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

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Feb 23, 2007
Posts: 1561
Cross-post: forums.sun.com thread

Please read the forum FAQ's, including the one regarding cross-posts: BeForthrightWhenCrossPostingToOtherSites
 
jQuery in Action, 2nd edition
 
subject: Not all content of ArrayList is written to the TextFile