Difference between System.err and System.out

     Most operating systems have three standard file descriptors: standard input, standard output, and standard error.

      The file descriptors of the three operating systems are mapped to the standard library of the programming language, often with a layer of packaging, but the names are usually called standard input, standard output, and standard error.

       The general way of writing in other languages ​​is: stdin, stdout, stderr (in some languages ​​uppercase, in some languages ​​lowercase). Corresponds to System.in, System.out, System.err in Java .

       At the language level the three file descriptors are all redirectable (if you want). But in general, if you use pipes or redirection in a unix shell or windows command line, it's just for standard input and output.

       In addition, one difference between standard output and standard error is that standard output is often cached, while standard error is not cached (the default setting can be changed). So if you use standard error to print things that can be displayed on the screen immediately, and standard output to print things may need to accumulate a few more characters before they can be printed together. You might see this problem if you mix stdout and stderr in your application.

       In general, System.out is used for normal output, that is, what the program really wants to output. And System.err is used for the output of error messages, which is what you don't expect to see.

        Therefore, the information typed by System.err often goes ahead of the System.out information. . .

like:

java code   favorite code
  1. public void sayHello(String name) {  
  2. System.err.println(new Date()+" sayHello method start");  
  3. System.out.println("excute sayHello()");  
  4. System.out.println(new Date()+" sayHello method end");  
  5. }  

There are two situations:

excute sayHello()
Mon Apr 26 10:12:05 CST 2010 sayHello method end
Mon Apr 26 10:12:05 CST 2010 sayHello method start

and

Mon Apr 26 10:17:15 CST 2010 sayHello method start
excute sayHello()

Mon Apr 26 10:17:15 CST 2010 sayHello method end


Original link: http://caoruntao.iteye.com/blog/653045

Guess you like

Origin blog.csdn.net/eyoulc123/article/details/52119372