Operating systems typically have three standard file descriptors: standard input, standard output, standard error
This is an abstract expression of the operating system
Different languages need to have different specific expressions, and of course it's just another packaging abstraction.
For example, C + + cin cout Cerr
In Java, it's system.in,system.out,system.err.
Example
Output Result:
----------------
----------------
It can be seen that:
Print information where err is run multiple times is not fixed
Look at the JDK documentation:
/*** the "standard" output stream. This stream was already * open and ready to accept output data. Typically this stream * corresponds to display output or another output destination * specified by the host Enviro Nment or user. * <p> * For simple stand-alone Java applications, a typical-to-write * a line of output data is: * & lt;blockquote><pre> * SYSTEM.OUT.PRINTLN (data) * </pre></blockquote> * <p> * See the <code>println</code> methods in class <code>printstream</code>. * * @seejava.io.printstream#println () *@seeJava.io.printstream#println (Boolean) *@seejava.io.printstream#println (char) *@seejava.io.printstream#println (char[]) *@seejava.io.printstream#println (Double) *@seejava.io.printstream#println (float) *@seejava.io.printstream#println (int) *@seejava.io.printstream#println (Long) *@seejava.io.printstream#println (java.lang.Object) *@seejava.io.printstream#println (java.lang.String)*/ Public Static FinalPrintStream out =NULL; /*** the "standard" error output stream. This stream was already * open and ready to accept output data. * <p> * Typically this stream corresponds to display output or another * output destination specified by the Host environment or user. by * Convention, this output stream was used to display the error messages * or other information the should come to T He immediate attention * of a user even if the principal output stream, the value of the * variable <code>ou T</code>, have been redirected to a file or other * destination that's typically not continuously monitored. */ Public Static FinalPrintStream err =NULL;
The two built-in variables of system are printstream types
Out
"Standard" output stream. This stream is open and ready to accept output data.
???? Typically, this stream corresponds to the display output or another output target specified by the host environment or user.
Err:
The "standard" error output stream. This stream is open and ready to accept output data.
???? Typically, this stream corresponds to the display output or another output target specified by the host environment or user.
???? By convention, this output stream is used to display error messages
???? Or show that even if the user output stream (the value of the variable out) has been redirected to a file or other target that is not normally monitored continuously, other information should be immediately brought to the attention of the user.
That is, out is used for output, and err is used for everything that you think is logically wrong, something that needs attention.
System.out has caching capabilities both in the JVM and in the operating system,
Is that your output is not necessarily real-time output, and sometimes accumulated to a certain amount will be output
System.err will be output in real time (default setting, can be changed)
This is why the Err print position is not fixed
If log4j logging is used and the error level is set, System.err will be logged and System.out will not
and generally use err in the IDE, it will change color, such as the red in eclipse
System.seterr () system.setout () can redirect both streams
System.setOut(new PrintStream(new FileOutputStream(new File( "d://out.txt "))));System.setErr(new PrintStream(new FileOutputStream(new File( "d://err.txt "))));
No output after redirection
Java standard output with standard error out with Err difference usage contact out in Java with err difference between System.out and system.err differences between SYSTEM.OUT.PRINTLN and SYSTEM.ERR.PRINTLN Java redirection System.out and System.err