PrintWriter 构造函数

PrintWriter constructors

我在下面列出了 PrintWriter class.
的 8 个构造函数 PrintWriter(File file), PrintWriter(File file, String csn), PrintWriter(OutputStream out), PrintWriter(OutputStream out, boolean autoFlush), PrintWriter(String fileName), PrintWriter(String fileName, String csn), PrintWriter(Writer out), PrintWriter(Writer out, boolean autoFlush).

问题:

  1. 如果没有采用 PrintStream 的 PrintWriter 构造器,那我们怎么能像我下面写的那样写一个语句呢?

  2. 如果没有采用 BufferedWriter 的 PrintWriter 构造器,那我们怎么能像我下面写的那样写一个语句?

          PrintWriter writer1 = new PrintWriter(System.out);
    
          PrintWriter writer2;
          writer2 = new PrintWriter(new BufferedWriter(new FileWriter(new File(outdir, reportFileName))));
    

提前致谢。

这是可能的,因为 PrintStream 继承自 FilterOutputStream,后者又继承自 OutputStream。

A BufferedWriter 继承自 Writer。

Writer 和 OutputStream 是 PrintWriter constructors. The big topic, what we are talking about here, is inheritance. There is a good post 中可能的变量。