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

forax at univ-mlv.fr forax at univ-mlv.fr
Fri Apr 27 11:43:24 UTC 2018


Hi Alan,

People do not read the documentation.
So adding something in the documentation about when a method should be used or not is never a solution.

Here the user want a String and provides a charset so you have no way but to decode the content to substitute the line separator.

cheers,
Rémi

----- Mail original -----
> De: "Alan Bateman" <Alan.Bateman at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>, "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:34:12
> Objet: Re: RFR (JDK11/NIO) 8201276: (fs) Add methods to Files for reading/writing a string from/to a file

> On 27/04/2018 12:29, Remi Forax wrote:
>> 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.
>>
> Yes, there are several discussion points around this and somewhat timely
> with multi-string support.
> 
> One thing that I think Joe will need in this API is some note to make it
> clearer what the intended usage is (as I think the intention is simple
> cases with mostly single lines of text).
> 
> -Alan.


More information about the core-libs-dev mailing list