System.err与System.out [重复]

时间:2023-02-15 17:46:13

This question already has an answer here:

这个问题在这里已有答案:

What is difference between

有什么区别

System.out.println("Programming");

and

System.err.println("Programming");

when both err and out are the object of Printstream class?

当err和out都是Printstream类的对象时?

3 个解决方案

#1


3  

These are different data streams. One is the so-called standard output stream (STDOUT), the other is the standard error stream (STDERR).

这些是不同的数据流。一个是所谓的标准输出流(STDOUT),另一个是标准错误流(STDERR)。

#2


1  

yes you are right by default both stream flushing the output in console but you can reassign this two stream to different channel. Like -

是的,默认情况下你都是正确的,在控制台中刷新输出,但你可以将这两个流重新分配到不同的通道。喜欢 -

System.setOut(new FileInputStream("outputfile.txt"));
System.setErr(new FileInputStream("errfile.txt"));

and try this -

试试这个 -

try{
   System.out.println("Try");
   int i =1/0;
}catch(Exception ex){
   System.err.println(ex);
}

#3


0  

You can filter t error and regular messages through the console. It's useful when you have few of one diluted in thousands of others.

您可以通过控制台过滤错误和常规消息。当你在成千上万的其他人中被稀释时,它很有用。

#1


3  

These are different data streams. One is the so-called standard output stream (STDOUT), the other is the standard error stream (STDERR).

这些是不同的数据流。一个是所谓的标准输出流(STDOUT),另一个是标准错误流(STDERR)。

#2


1  

yes you are right by default both stream flushing the output in console but you can reassign this two stream to different channel. Like -

是的,默认情况下你都是正确的,在控制台中刷新输出,但你可以将这两个流重新分配到不同的通道。喜欢 -

System.setOut(new FileInputStream("outputfile.txt"));
System.setErr(new FileInputStream("errfile.txt"));

and try this -

试试这个 -

try{
   System.out.println("Try");
   int i =1/0;
}catch(Exception ex){
   System.err.println(ex);
}

#3


0  

You can filter t error and regular messages through the console. It's useful when you have few of one diluted in thousands of others.

您可以通过控制台过滤错误和常规消息。当你在成千上万的其他人中被稀释时,它很有用。