How do you produce a new line in FileWriter? It seems that "\n" does not work.
log = new FileWriter("c:\\" + s.getInetAddress().getHostAddress() + ".txt", true);
log.append("\n" + Long.toString(fileTransferTime));
log.close();
The file output of the code above is just a long string of numbers without the new line.
I'll take a wild guess that you're opening the .txt
file in Notepad, which won't show newlines with just \n
.
Have you tried using your system-specific newline character combination?
log.append(System.getProperty("line.separator") + Long.toString(fileTransferTime));
You should either encapsulate your FileWriter
into a PrintWriter
if your goal is to have a formated content, println()
will help you. Or use the system property line.separator
to have a separator adapted to your Operating System.
System.getProperty("line.separator")
Resources :
System.getProperty
I'm using "\r\n" and it works great for me. Even when opening .txt document in notepad;)
Try changing \t
to \n
in the second line.
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