-
Please help me out here
consider the following program segment..
FileWriter f=new FileWriter(args[0]);
............
..........
f.write('\n');
The above given segment is from one of my programs.whenever I use f.write('\n') to go to a new line in the output file,the function is printing a small square box in the file.But,I want it to move the control to a new line so that whatever character it writes in the file thereafter writes it in a new line.This is happening for all the escape sequences used.Can anybody give me a solution for this problem?Reply soon.Thanq....
-
"\n" is not a platform independent way of writing a new line to a file. Try using:
Code:
f.write(System.getProperty("line.separator"));
Here are some relevant javadocs:
BufferedWriter.html#newLine()
System.html#getProperties()
-
Thanks for the reply.What about using other escape sequences like '\b'(Whitespace)?
-
The problem is not escape sequences! They are same on all platforms. The problem is the new line for files! As far as i remember it was \r\n (Linux i guess) in one platform and \n (Windows i guess) in the other one.