日期:2014-05-20  浏览次数:20683 次

有关System.out和System.err的源码
两个问题:
    1     请教下System.err是怎么做到用红颜色字体输出的?
    2     关于这两者的源码问题:
          可以看到在System这个类中的out和err两个属性定义如下:
          public   final   static   PrintStream   out   =   nullPrintStream();
          public   final   static   PrintStream   err   =   nullPrintStream();

          nullPrintStream()方法定义如下:
          private   static   PrintStream   nullPrintStream()   throws   NullPointerException   {

                  if   (currentTimeMillis()   >   0)
        return   null;
throw   new   NullPointerException();
        }
        这里为什么直接返回一个null,如果这里返回是null的话,System.out和System.err是怎么工作的?
        谢谢

------解决方案--------------------
System.out和System.err只是两个文件描述符,颜色的事情是由更上层的终端处理。