Home » questions » Help please please ! writing file in java?

Help please please ! writing file in java?

2006-08-01 01:27:11, Category: Programming & Design
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 :)

Answers

  1. shin

    On 2006-08-01 01:33:41


    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".
  2. Venkatraman M

    On 2006-08-01 01:37:28


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

    On 2006-08-01 13:29:48


    //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();