File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with writing texts in new line

 
Jahangir Alam
Greenhorn
Posts: 15
Java Netbeans IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ahsan Bagwan
Ranch Hand
Posts: 247
1
Java MySQL Database Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47270
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic