RFR (JDK11/NIO) 8201276: (fs) Add methods to Files for reading/writing a string from/to a file
Remi Forax
forax at univ-mlv.fr
Fri Apr 27 11:29:39 UTC 2018
I think that having a readString that includes OS dependent line separators is a mistake,
Java does a great job to try to shield the developer from the kind of things that makes programs behave differently on different platforms.
readString should subtitute (\r)?\n to \n otherwise either people will do a call replace() which is less efficient or will learn the lesson the hard way.
raw string literal does the same substitution for the same reason.
regards
Rémi
----- Mail original -----
> De: "Alan Bateman" <Alan.Bateman at oracle.com>
> À: "Joe Wang" <huizhe.wang at oracle.com>
> Cc: "nio-dev" <nio-dev at openjdk.java.net>, "core-libs-dev" <core-libs-dev at openjdk.java.net>
> Envoyé: Vendredi 27 Avril 2018 13:13:52
> Objet: Re: RFR (JDK11/NIO) 8201276: (fs) Add methods to Files for reading/writing a string from/to a file
> 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.
>
> 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.
>
> 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.
>
> -Alan
More information about the core-libs-dev
mailing list