印刷方法を使用できる場合は、PrintWriterがFileOutputStreamで使用するのはなぜですか。

StackOverflow https://stackoverflow.com/questions/9528536

質問

これを行うことができれば:

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