解决方案 »

  1.   

    看源代码就知道。
    最终差别就在boolean autoFlush    第一true  第二false
    private PrintStream(boolean autoFlush, OutputStream out) {
            super(out);
            this.autoFlush = autoFlush;
            this.charOut = new OutputStreamWriter(this);
            this.textOut = new BufferedWriter(charOut);
        }
      

  2.   


        public PrintStream(File file) throws FileNotFoundException {
            this(false, new FileOutputStream(file));
        }    public PrintStream(OutputStream out) {
            this(out, false);
        }    public PrintStream(OutputStream out, boolean autoFlush) {
            this(autoFlush, requireNonNull(out, "Null output stream"));
        }    private PrintStream(boolean autoFlush, OutputStream out) {
            super(out);
            this.autoFlush = autoFlush;
            this.charOut = new OutputStreamWriter(this);
            this.textOut = new BufferedWriter(charOut);
        }
    两者确实一样,因为你传file进去,它内部也会创建一个FileOutputStream
      

  3.   

    楼上最后的私有方法是什么意思啊
     
        private PrintStream(boolean autoFlush, OutputStream out) {
            super(out);
            this.autoFlush = autoFlush;
            this.charOut = new OutputStreamWriter(this);
            this.textOut = new BufferedWriter(charOut);
        }