且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Printwriter和OutputStream有什么区别?

更新时间:2023-12-04 12:01:04

OutputStreams are meant for binary data. Writers (including PrintWriter) are meant for text data.

You may not see the difference in your specific situation as you're calling PrintWriter.write(int) which writes a single character - if the character encoding you're using just maps characters to the same byte, for characters less than 127, then you'll see the same result. But if you give it a different encoding, then you'll see a difference.

PrintWriter is also different in that it suppresses IO exceptions - as does PrintStream, which is the binary stream equivalent of PrintWriter.

相关阅读

推荐文章