Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8198790

Add constructors with Charset parameter for FileReader and FileWriter

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 11
    • core-libs
    • None
    • minimal
    • There is no compatibility risk. Only new methods are proposed.
    • Java API
    • SE

      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

            joehw Joe Wang
            webbuggrp Webbug Group
            Roger Riggs, Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: