RFR (JDK11/NIO) 8201276: (fs) Add methods to Files for reading/writing a string from/to a file

Joe Wang huizhe.wang at oracle.com
Fri Apr 27 19:02:50 UTC 2018

On 4/27/2018 4:13 AM, Alan Bateman wrote:
> On 27/04/2018 05:50, Joe Wang wrote:
>> Hi,
>> We're looking into adding methods to Files to read a file into a 
>> String/write a String to a file. Below is the current proposal. 
>> Please review.
>> JBS: https://bugs.openjdk.java.net/browse/JDK-8201276
>> webrev: http://cr.openjdk.java.net/~joehw/jdk11/8201276/webrev/
>> specdiff: 
>> http://cr.openjdk.java.net/~joehw/jdk11/8201276/specdiff/java/nio/file/Files.html
> The javadoc for these 4 methods looks okay. It might be helpful to 
> include something in the readString javadoc to make it absolutely 
> clear that the String may include line separators. I assume the "Note 
> that .." paragraph can be changed to an @apiNote.

Added a statement to indicate that "the resulting string will contain 
line separators as they appear in the file".
Changed the 'note' to @apiNote.

> I assume you'll add "@since 11" to the readString methods.

> It would be good to keep the existing formatting/style consistent with 
> the existing code if you can, e.g. <p> tags, 4 space indent rather 
> than 8 for the throws, etc.

Fixed <p> and the throws. I didn't even notice that the IDE (NetBeans) 
added 8 spaces!

> I can't tell from your mail if you are just looking for feedback on 
> the current implementation + tests or just the API. I assume there are 
> alternatives to using StringBuilder for the readString methods for 
> example.

Both. I thought webrevs would be helpful where specdiff was not clear 
enough, for example, you won't otherwise notice the formatting/style 
issue :-)

I changed that to new String(readAllBytes(path), charset) as it's 
convenient with readAllBytes handling all situations (OOM and etc.). But 
alternative solution to avoid copying would be nice.


> -Alan

More information about the core-libs-dev mailing list