From the Javadoc for PrintWriter
:
Unlike the PrintStream class, if automatic flushing is enabled it will be done only when one of the println, printf, or format methods is invoked, rather than whenever a newline character happens to be output. These methods use the platform's own notion of line separator rather than the newline character.
If you're using .print()
you have to manually .flush()
. Simply having \n
or \r\n
in your String
does not do so which is what is causing the different behavior you see.