The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Problem skipping to new line in text file

Posted by Farooq on November 27, 2000 at 4:41 AM

My problem is that while writing to a text file I want to skip to a new line after some text.

In place of newline characters it is printing small boxes[a sign that it doesnt recognize new line]
But it works when I use Tab \t

The code is:


public class CharFileIOApp {

public static void main(String args[]) throws IOException {
FileWriter outStream = new FileWriter("testfile.txt");
String s = "This is a test.\n" + "It will help \n" + " to increase ur aptitude\n";
for(int i=0;i outStream.write(s.charAt(i));

I want the output of this to be like this:

This is a test.
It will help
to increase ur aptitude

But I am getting the output as:

This is a test. It will help to increase ur aptitude


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us