62,616
社区成员
发帖
与我相关
我的任务
分享
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进去,它内部也会创建一个FileOutputStreamprivate PrintStream(boolean autoFlush, OutputStream out) {
super(out);
this.autoFlush = autoFlush;
this.charOut = new OutputStreamWriter(this);
this.textOut = new BufferedWriter(charOut);
}