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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With