Summary
Add constructors for the FileReader and FileWriter that take a Charset parameter.
Problem
The FileReader and FileWriter were designed as a convenient API for situations where default settings are desirable. However, that assumption was flawed since assuming the platform's default Charset can often cause confusion and lead to error-prone code in situations where the default Charset is not appropriate.
Solution
Add constructors that explicitly take a Charset parameter. This solution provides developers with a means to specify the Charset, as well as a clear API indicating that a Charset shall be specified in most cases.
Specification
Below is a summary of the proposed changes. The specdiff zip file is attached. It can be viewed at:
http://cr.openjdk.java.net/~joehw/jdk11/8183554/specdiff/overview-summary.html
- java/io/FileReader
public FileReader(String fileName, Charset charset) throws FileNotFoundException
public FileReader(File file, Charset charset) throws FileNotFoundException
- java/io/FileWriter
public FileWriter(String fileName, Charset charset) throws IOException
public FileWriter(String fileName, Charset charset, boolean append) throws IOException
public FileWriter(File file, Charset charset) throws IOException
public FileWriter(File file, Charset charset, boolean append) throws IOException
- csr of
-
JDK-8183554 Add constructors with Charset parameter for FileReader and FileWriter
-
- Resolved
-