如果我可以这样做:

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top