JDK-8277357 : Release Note: Default charset for PrintWriter That Wraps PrintStream
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 18
  • Priority: P4
  • Status: Closed
  • Resolution: Delivered
  • OS: generic
  • CPU: generic
  • Submitted: 2021-11-17
  • Updated: 2022-02-10
  • Resolved: 2022-02-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 18
18Resolved
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.