Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

printing a new line to file

 
jam hall
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using a PrintWriter object to print a report to file the \n(new line) control character doesn't seem to do anything but \t(tab) does.

Is there another way to print a new line?

Thanks ahead
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with calling the println() method?
 
Julien Grenier
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing you are on windows. The newlines in windows are form with 2 caracters the \n and the \r so you need to write both like this \n\r to produce a new line.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the end-of-line sequence varies between different operating systems, you should use the following to make your program system-independent.



Now the variable called newline contains the system-dependant end-of-line sequence. The Java API may have a static variable that serves the same purpose hiding somewhere, but I was unable to find it.

HTH

Layne
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic