System.out based on PrintStream , which by default is reset whenever a new line is written.
From javadoc :
autoFlush - logical; if true, the output buffer will be flushed whenever an array of bytes is written, one of the println methods is called, or a newline or byte character is written ( '\n' )
Thus, the println case you described is explicitly handled, and the write case with byte[] also guaranteed to be cleared, because it falls under "whenever the byte array is written."
If you replace System.out with System.setOut and donβt use the autocomplete stream, then you will need to clear it like any other stream.
The library code probably should not use System.out directly, but if it is, then it should be careful because the library user can override System.out to use the stream without clearing it.
Any Java program that writes binary output to System.out should be careful until flush before exit , because binary output often does not include a terminating new line.
Mike Samuel Aug 23 '11 at 19:19 2011-08-23 19:19
source share