What is difference between
System.out.println("Programming");
and
System.err.println("Programming");
when both err
and out
are the object of Printstream
class?
What is difference between
System.out.println("Programming");
and
System.err.println("Programming");
when both err
and out
are the object of Printstream
class?
These are different data streams. One is the so-called standard output stream (STDOUT), the other is the standard error stream (STDERR).
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);
}
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.