File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "printing a new line to file" Watch "printing a new line to file" New topic

printing a new line to file

jam hall

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

Joined: Jul 08, 2003
Posts: 24199

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.



Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: printing a new line to file
It's not a secret anymore!