JDK-8201276 : (fs) Add methods to Files for reading/writing a string from/to a file
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.nio
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-04-07
  • Updated: 2018-06-26
  • Resolved: 2018-06-13
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 11
11 b19Fixed
Related Reports
CSR :  
Relates :  
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.