Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8276970 Default charset for PrintWriter that wraps PrintStream
  3. JDK-8277357

Release Note: Default charset for PrintWriter That Wraps PrintStream

    XMLWordPrintable

Details

    • generic
    • generic
    • Verified

    Description

      The `java.io.PrintStream`, `PrintWriter`, and `OutputStreamWriter` constructors that take a `java.io.OutputStream` and no charset now inherit the charset when the output stream is a `PrintStream`. This is important for usages such as:
      ```
      new PrintWriter(System.out)
      ```
      where it would be problematic if `PrintStream` didn't use the same charset as that used by `System.out`. This change was needed because [JEP 400](https://openjdk.java.net/jeps/400) makes it is possible, especially on Windows, that the encoding of `System.out` is not UTF-8. This would cause problems if `PrintStream` were wrapped with a `PrintWriter` that used UTF-8.

      As part of this change, `java.io.PrintStream` now defines a `charset()` method to return the print stream's charset.

      Attachments

        Activity

          People

            naoto Naoto Sato
            naoto Naoto Sato
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: