Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6852033 Inputs/Outputs methods to make common I/O tasks easy to do
  3. JDK-8201276

(fs) Add methods to Files for reading/writing a string from/to a file

    XMLWordPrintable

    Details

    • Type: Sub-task
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b19

      Backports

        Description

        Reading the content of a file into a string and writing a string text to a file are common operations. This enhancement suggests adding the following methods:

        String Files.readString(Path path)
        String Files.readString(Path, Charset)

        Path Files.write(Path, CharSequence, OpenOption...)
        Path Files.write(Path, CharSequence, Charset, OpenOption...)

        In addition, a utility method that compares two files:
        Files.isSameContent(path1, path2)

        There will be a further research on String operations as relevant to the File operations to determine whether there are legitimate alternative approaches to the above. For example, specifying start/end index to limit the range to be read, which allows applications to control the size of the returning string. Or, treating the content of a file as having sections, and therefore return a list of strings instead.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  joehw Joe Wang
                  Reporter:
                  joehw Joe Wang
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: