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

Add constructors with Charset parameter for FileReader and FileWriter

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      There is no compatibility risk. Only new methods are proposed.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: