jdk文档中说PrintStream用来输出字节,PrintWriter用来输出字符,而且特别强调 The PrintWriter class should be used in situations that require writing characters rather than bytes. 但是为什么System.out却使用了PrintStream而不是PrintWriter?难道控制台输出就不是字符了吗
这两个类到底什么时候该用哪个,求讲解
(本人初学的),看了区别后还是不懂什么意思

解决方案 »

  1.   

    PrintWriter 里面 包含了 PrintStream。
     /**
         * The "standard" output stream. This stream is already
         * open and ready to accept output data. Typically this stream
         * corresponds to display output or another output destination
         * specified by the host environment or user.
         * <p>
         * For simple stand-alone Java applications, a typical way to write
         * a line of output data is:
         * <blockquote><pre>
         *     System.out.println(data)
         * </pre></blockquote>
         * <p>
         * See the <code>println</code> methods in class <code>PrintStream</code>.
         *
         * @see     java.io.PrintStream#println()
         * @see     java.io.PrintStream#println(boolean)
         * @see     java.io.PrintStream#println(char)
         * @see     java.io.PrintStream#println(char[])
         * @see     java.io.PrintStream#println(double)
         * @see     java.io.PrintStream#println(float)
         * @see     java.io.PrintStream#println(int)
         * @see     java.io.PrintStream#println(long)
         * @see     java.io.PrintStream#println(java.lang.Object)
         * @see     java.io.PrintStream#println(java.lang.String)
         */
        public final static PrintStream out = nullPrintStream();
      

  2.   

    PrintWriter 里面 包含了 PrintStream。
     /**
         * The "standard" output stream. This stream is already
         * open and ready to accept output data. Typically this stream
         * corresponds to display output or another output destination
         * specified by the host environment or user.
         * <p>
         * For simple stand-alone Java applications, a typical way to write
         * a line of output data is:
         * <blockquote><pre>
         *     System.out.println(data)
         * </pre></blockquote>
         * <p>
         * See the <code>println</code> methods in class <code>PrintStream</code>.
         *
         * @see     java.io.PrintStream#println()
         * @see     java.io.PrintStream#println(boolean)
         * @see     java.io.PrintStream#println(char)
         * @see     java.io.PrintStream#println(char[])
         * @see     java.io.PrintStream#println(double)
         * @see     java.io.PrintStream#println(float)
         * @see     java.io.PrintStream#println(int)
         * @see     java.io.PrintStream#println(long)
         * @see     java.io.PrintStream#println(java.lang.Object)
         * @see     java.io.PrintStream#println(java.lang.String)
         */
        public final static PrintStream out = nullPrintStream();
      

  3.   

    PrintWriter 里面 包含了 PrintStream。
     /**
         * The "standard" output stream. This stream is already
         * open and ready to accept output data. Typically this stream
         * corresponds to display output or another output destination
         * specified by the host environment or user.
         * <p>
         * For simple stand-alone Java applications, a typical way to write
         * a line of output data is:
         * <blockquote><pre>
         *     System.out.println(data)
         * </pre></blockquote>
         * <p>
         * See the <code>println</code> methods in class <code>PrintStream</code>.
         *
         * @see     java.io.PrintStream#println()
         * @see     java.io.PrintStream#println(boolean)
         * @see     java.io.PrintStream#println(char)
         * @see     java.io.PrintStream#println(char[])
         * @see     java.io.PrintStream#println(double)
         * @see     java.io.PrintStream#println(float)
         * @see     java.io.PrintStream#println(int)
         * @see     java.io.PrintStream#println(long)
         * @see     java.io.PrintStream#println(java.lang.Object)
         * @see     java.io.PrintStream#println(java.lang.String)
         */
        public final static PrintStream out = nullPrintStream();
      

  4.   

    同问,知道System.out是返回PrintStream类型的数据
      

  5.   

    PrintStream.print(String) (使用系统默认编码将chars转换为bytes)这用法和Writer都是输出字符,区别是前者依赖了系统默认编码,而后者可以由用户指定,所以前者在这方面使用上没有后者合适(对具体平台的依赖在移植时可能会产生问题),但因为历史原因,早在jdk1.1 reader/writer引入前已被引入,一直沿用着。