Introduction to the difference between printstream and printwriter
The APIs of printstream and printwriter are almost the same, both of which can output various forms of data, and the construction methods are almost the same
Printwriter has more than one accepted writer parameter
API comparison:
So, what is the difference between them? From stackflow
The main meaning is that the functions of the two classes are basically the same. Printwriter that printstream can do can also be implemented, and the function of printwriter is more powerful. However, due to the late appearance of printwriter, the earlier system Out is implemented using printstream, so printstream is not discarded for compatibility.
The biggest difference between the two classes is that printstream uses the system default encoding format when outputting characters and converting characters into bytes. In this way, problems and uncontrollable factors will occur when data is transmitted to another platform and decoded by another encoding format. The printwriter can be used when passing in the writer
The following program shows how printstream and printwriter handle the same output destination. The program will display four characters of "simplified Chinese" on the screen:
summary
The above is all about the difference between printstream and printwriter in this article. I hope it will be helpful to you. Interested friends can continue to refer to other related topics on this site. If there are deficiencies, please leave a message to point out. Thank you for your support!