当我只能使用打印方法时,为什么打印机通常与FileOutputStream一起使用
-
16-11-2019 - |
题
如果我可以这样做:
PrintWriter pw = new PrintWriter("file.txt");
pw.println("Hello");
.
为什么PW经常像这样使用:
PrintWriter pw = new PrintWriter(new FileOutputStream("file.txt"));
pw.println("Hello");
.
有什么区别?
解决方案
The PrintWriter
constructors that accept a file name or a java.io.File
are relatively new; they were added in JDK 1.5. The FileOutputStream
or FileWriter
version used to be the only alternative; a lot of people don't even know about the new constructors in PrintWriter.
不隶属于 StackOverflow