Reputation: 849
If I can do this:
PrintWriter pw = new PrintWriter("file.txt");
pw.println("Hello");
Why PW is often use like this:
PrintWriter pw = new PrintWriter(new FileOutputStream("file.txt"));
pw.println("Hello");
What's the difference?
Upvotes: 3
Views: 3267
Reputation: 81684
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.
Upvotes: 3