从技术上讲,它不是BufferedWriter
. 它直接扩展Writer
。也就是说,它似乎可以使用 aBufferedWriter
取决于您调用的构造函数。例如,查看传入 a 的构造函数String
:
public PrintWriter(String fileName) throws FileNotFoundException {
this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName))),
false);
}
此外,您没有使用已链接到的 javadoc 的构造函数。您已经使用了带有Writer
. 那个人似乎没有使用BufferedWriter
. 这是它的源代码:
/**
* Creates a new PrintWriter, without automatic line flushing.
*
* @param out A character-output stream
*/
public PrintWriter (Writer out) {
this(out, false);
}
/**
* Creates a new PrintWriter.
*
* @param out A character-output stream
* @param autoFlush A boolean; if true, the <tt>println</tt>,
* <tt>printf</tt>, or <tt>format</tt> methods will
* flush the output buffer
*/
public PrintWriter(Writer out,
boolean autoFlush) {
super(out);
this.out = out;
this.autoFlush = autoFlush;
lineSeparator = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("line.separator"));
}