English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i am writing to a file and want to enter a new line, for example:
FileWriter output = new FileWriter(FILE,true); //where FILE is my file

output.write("\n hello");

output.write("\n java");

output.close();

I want this to be on the file

:hello
:java

instead im getting
:hello[]java

in other words how do i omit writing the "\n" character and actually making a new line

please help thanxs :)

2006-07-31 21:27:11 · 3 answers · asked by dragongml 3 in Computers & Internet Programming & Design

3 answers

try

output.write("\r\n hello");
output.write("\r\n java");

2006-07-31 21:37:28 · answer #1 · answered by Venkatraman M 2 · 1 0

//appropriate exception-handling code omitted
BufferedWriter bw = new BufferedWriter(new FileWriter(FILE, true));

bf.write(hello);

bf.newLine();
/*From the newLine() Javadoc: Write a line separator. The line separator string is defined by the system property line.separator, and is not necessarily a single newline ('\n') character.
*/

bf.write(java);

bf.close();

2006-08-01 09:29:48 · answer #2 · answered by vincentgl 5 · 0 0

Try using this:

\x0D\x0A

instead of \n

Another common problem is the use of '\n' when communicating using an Internet protocol that mandates the use of ASCII CR+LF for ending lines. Writing '\n' to a text mode stream works correctly on Windows systems, but produces only LF on Unix, and something completely different on more exotic systems. Using "\r\n" in binary mode is slightly better, as it works on many ASCII-compatible systems, but still fails miserably in the general case. One approach is to use binary mode while directly specifying the desired numerical values of the ASCII control sequence, "\x0D\x0A".

2006-07-31 21:33:41 · answer #3 · answered by shin 3 · 0 0

fedest.com, questions and answers