• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Make JAVA IO methods recognize new line? "\n"  RSS feed

 
Adeiza Yusuf
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please is there any way to make the methods in some of the JAVA.IO classes recognize the a newline("\n") in a string passed to its argument, I have tried several but they seem to ignore it and just print in a straight line.



the output in a file is as follows:-- please print in two lines this is a second line

instead of

:--Please print in two lines
this is a second line.


Why does it not Recognize "\n"?

 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you printing to? And what is your environment (windows/linux/...) Also try System.getProperty("line.separator"); instead of \n
 
Adeiza Yusuf
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote:Where are you printing to? And what is your environment (windows/linux/...) Also try System.getProperty("line.separator"); instead of \n


am printing to a text file using a window Operating system. This is amazing! just tried that out and it worked. i could never have guessed.

Thank you. SOLVED

 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad I could help.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since Java 1.5 you can use PrintWriter's prinf method as well:
%n will automatically be replaced by the line.separator system property.
 
Adeiza Yusuf
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Since Java 1.5 you can use PrintWriter's prinf method as well:
%n will automatically be replaced by the line.separator system property.


don't to believe it could be that easy until i try it out. thanks for the contribution anyway. it is good have several ways of doing same thing.
 
Adeiza Yusuf
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Since Java 1.5 you can use PrintWriter's prinf method as well:
%n will automatically be replaced by the line.separator system property.


don't want to believe it could be that easy until i try it out. thanks for the contribution anyway. it is good have several ways of doing same thing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!