wood burning stoves*
The moose likes Beginning Java and the fly likes printing a new line to file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "printing a new line to file" Watch "printing a new line to file" New topic
Author

printing a new line to file

jam hall
Greenhorn

Joined: Sep 06, 2005
Posts: 4
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

Joined: Jul 08, 2003
Posts: 24168
    
  30

What's wrong with calling the println() method?


[Jess in Action][AskingGoodQuestions]
Julien Grenier
Ranch Hand

Joined: Sep 01, 2005
Posts: 41
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

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: printing a new line to file
 
Similar Threads
Problem in reading empty line
Jython Grief
SCJP Brainteaser (11)
system.out.print vs println
printing new line in file