Bringing all file operations together into one place
Alan.Bateman at oracle.com
Thu Jan 13 03:03:39 PST 2011
Rémi Forax wrote:
> First, I think this version of the API easier to use.
Thanks for spending time on it.
> Some comments about java.nio.file.Files:
> readAttributes(Path <http://openjdk.java.net/projects/nio/javadoc/java/nio/file/Path.html> path, String <http://download.java.net/jdk7/archive/b123/docs/api/java/lang/String.html?is-external=true> attributes, LinkOption <http://openjdk.java.net/projects/nio/javadoc/java/nio/file/LinkOption.html>... options)
> should returns a Map<String,Object> if possible.
> Map<String,?> will let users deal with wildcard capture.
> As an exercise, try to find the type XXX in this code:
> XXX entrySet = readAttributes(path, attributes, options).entrySet();
I thought that one was fixed a long time ago but it seems not. Thanks
for bringing it up. I'll include this in this round of updates.
> 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.
> 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.
Thanks again (as always).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the nio-dev