aspose file tools*
The moose likes Beginning Java and the fly likes Problem with writing texts in new line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with writing texts in new line" Watch "Problem with writing texts in new line" New topic
Author

Problem with writing texts in new line

Jahangir Alam
Greenhorn

Joined: Aug 18, 2013
Posts: 15

Hi,

I want to write some texts into a student.txt file. I have written a program and it works fine. But all the information are being written into a single line. I want each in separate line.

Here is the part of code:



I added "\n", but it did not work.

Any help would be great for me!


Sorry for my bad English!
Ahsan Bagwan
Ranch Hand

Joined: Oct 05, 2010
Posts: 162
One solution would be to wrap your FileWriter object in a BufferedWriter object and then use a newLine() method after every write().
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
Another option is a Formatter which can write all those details in to a text file. You can pass the File object to its constructor, or a stream leading to that file. You may have to handle a FileNotFoundException.

Why are you parsing a String to an int and immediately converting it back to a String with the + operator? Why not simply use trim() and add the Strings with +.

Doug Slavens
Greenhorn

Joined: Sep 10, 2013
Posts: 11
Try replacing FileWriter with PrintWriter. PrintWriter has println methods which will print the output of each call on a new line.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with writing texts in new line