下面的一段程序:
public static void main(String[] args) {
for(int i = 0;i < 10;i++) {
System.out.println(i);
System.err.println(k);
}
}如上的程序输出为什么不是一黑一红呢,而是每次执行后输出的效果都不一样呢?
public static void main(String[] args) {
for(int i = 0;i < 10;i++) {
System.out.println(i);
System.err.println(k);
}
}如上的程序输出为什么不是一黑一红呢,而是每次执行后输出的效果都不一样呢?
* The "standard" error output stream. This stream is 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 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 <code>out</code>, has been redirected to a file or other
* destination that is typically not continuously monitored.
*/
public final static PrintStream err = nullPrintStream();注意这句this output stream is used to display error messages
or other information that should come to the immediate attention
of a user even if.....out, has been redirected to 实际上无论你在err.print前加多少次打印的信息,程序总会让用户在第一时间看到err信息,毕竟,这是可能导致程序崩溃的信息,需要第一时间让用户知道
如果是err.print是一个高优先级的操作的话,为什么出来的是随即的呢?
to:pdvv(我爱猫猫):
多谢关注,如你所说,期待更多人的讨论:)其实我也是无意当中看到这个东西,想不明白就上来问问,不知道这个问题在实际的应用中到底有什么作用,我也就不得而知了