out
The "standard" output stream. This stream is already open and ready to accept output data. Typically this stream corresponds to display output or another output destination specified by the host environment or user.
err
Typically this stream corresponds to display output or another output destination specified by the host environment or user. By convention, this output stream is used to display error messages or other information that should come to the immediate attention of a user even if the principal output stream, the value of the variable out, has been redirected to a file or other destination that is typically not continuously monitored.
The "standard" output stream. This stream is already open and ready to accept output data. Typically this stream corresponds to display output or another output destination specified by the host environment or user.
err
Typically this stream corresponds to display output or another output destination specified by the host environment or user. By convention, this output stream is used to display error messages or other information that should come to the immediate attention of a user even if the principal output stream, the value of the variable out, has been redirected to a file or other destination that is typically not continuously monitored.
而System.err.println只能在屏幕上实现打印,即使你重定向了也一样。
当输出一个流时,JVM和操作系统共同决定何时输出这个流。也就是说,尽管开发者键入了:
System.out.print_
("Test Output:");
JVM和操作系统的组合体并不会立即输出这个流。相反,它将保持等待状态直到将要输出的东西达到一定的量。
假设输入以下指令:
System.out.println("Debugging Info.");
JVM可能同意输出;然而,操作系统可能决定暂不输出。
由于这个原因,在调试程序时想要发现出错的位置就有可能成为问题。考虑以下的程序:for(int i=0; i<56; i++) {
System.out.println(i);
... // containing an error
}
错误可能出现在i等于54时,但是可能JVM在i等于49时就结束输出了。50到54仍然存在于缓存中,结果也就丢失了。使用System.err来报告错误、调试程序就可以避免这种情况出现,它将使每一次操作的结果都输出出来。例如以下程序:for(int i=0; i<56; i++) {
System.err.println(i);
... // containing an error
}
在每一次i等于54时都将显示错误信息。
System.out是蓝色的.
谢谢
以前也碰到这样的问题
System.out.println()打印不出来东东
现在知道了:-)
调试的时候用
java -cp classpath MyClass >out.txt 2>err.txt这样运行以后,System.out.println就输出到了out.txt中,System.err.println就输出到err.txt中这才是两者的区别!所以你应该尽量保证你的意思是正确的,即out是一般性的输出,err是当出现错误的时候才使用的输出