Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"\n" not working when exported to .jar file

I have an output file for a program I have written. It is written by a FileWriter and BufferedWriter.

    FileWriter errout = new FileWriter(new File("_ErrorList.txt"));
    BufferedWriter out = new BufferedWriter(errout);

Later I write to the file using lines similar to.

    out.write("Product id:" + idin + " did not fetch any pictures.\n ");

When I simpily run the program in Eclipse, the output file is formatted correctly, with each message being written on a new line. However when I export to a .jar file, it no longer works and puts every message on a single line, as if the "\n" was not working.

Am I using the FileWriter/BufferedWriter incorrectly, or does it not work in a .jar file?

like image 311
user1816892 Avatar asked Jan 15 '23 00:01

user1816892


1 Answers

You should not use '\n' directly. Either use out.newLine() to introduce a line break, or wrap the BufferedWriter into a PrintWriter, and use out.println().

This has nothing to do with the .jar file, anyway. More likely is Eclipse being clever and showing you line breaks, while the operating system does not.

like image 59
Flavio Avatar answered Jan 25 '23 12:01

Flavio