Bringing all file operations together into one place
Rémi Forax
forax at univ-mlv.fr
Thu Jan 13 03:23:04 PST 2011
On 01/13/2011 12:03 PM, Alan Bateman wrote:
> Rémi Forax wrote:
>> :
>> First, I think this version of the API easier to use.
> Thanks for spending time on it.
[...]
>
>>
>> readLines: why not returning a lazy Collection instead of a List.
>> if a user want a List, this code
>> List<String> lines = new ArrayList<>(Files.readLines(...))
> Like readBytes (or readAllBytes as you've suggested), this method
> reads the entire file so I didn't make it lazy. An Iterable<String>
> might be better but I initially proposed it as List so that it could
> be used as such if needed.
>
>
>> Or perhaps better, wait jdk 8 and the stream API.
>>
>> readBytes() can be renamed to readAllBytes().
> Maybe, it was originally readAllBytes way back.
I think I prefer readAllBytes and readAllLines. And future will tell if
lazy versions will be added later.
>
>>
>> write(...): javadoc should also contains an example showing how to
>> create a new File:
>> Files.write(path, bytes, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
>>
>> because I'm sure that users will forget TRUNCATE_EXISTING.
> This is the default if you don't specify any options ("That is, if no
> options are present then file is created if it doesn't exist or is
> first truncated to a size of 0 if it exists"). The idea is that you
> shouldn't need to specify any ideas for the common case, ie:
> Files.write(path, bytes). Maybe I need to make that clearer in the docs.
Perhaps just something saying that this is equivalent to
write(WRITE|CREATE|TRUNCATE_EXISTING)
>
> Thanks again (as always).
>
> -Alan
>
>
cheers,
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20110113/5f4d6717/attachment.html
More information about the nio-dev
mailing list