The difference between PrintStream and PrintWriter __printstrea

Source: Internet
Author: User

PrintStream and PrintWriter APIs are almost identical, and can output all forms of data in almost the same way

PrintWriter to accept writer parameters.

API comparisons:

So, what is the difference between them? From Stackflow


The main meaning is that 2 classes function basically the same, PrintStream can do printwriter also can be achieved, and PrintWriter function more powerful. But because PrintWriter appears late, earlier System.out use PrintStream to achieve, so in order to be compatible there is no discarded printstream.
The biggest difference between the 2 classes is that printstream in the output character, converting characters to bytes using the system's default encoding format, which can cause problems when data is transferred to another platform and another platform decodes with another encoding format, which is an uncontrollable factor. The PrintWriter can be encoded when the programmer specifies the characters to be converted to bytes when the writer is passed in, so that compatibility and controllability are better.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.