Missing delete path facility
Alan Bateman
Alan.Bateman at Sun.COM
Tue Oct 6 05:18:55 PDT 2009
Ulf Zibis wrote:
> Hi all,
>
> in the new nio API there is Path#delete(). It only allows to delete a
> single file or directory if empty.
> If developer wants to delete a complete subtree of a path, he has to
> programmatically iterate over all its elements.
>
> Please add functionality to save developers from hand-coding those
> iterations.
This has come up a few times and is a good candidate to add to the Files
utility class. Like all composite operations, the question arises as to
what to an operation fails. If you are writing a command-line tool (like
rm -r) then you would emit a warning message and continue. Other
approaches are to terminate, or to continue and return a collection of
the files that could not be deleted (and the reason). But point taken
that developers shouldn't have to re-invent this. In the mean-time, it's
actually not that hard and there is a skeleton example in FileVisitor's
javadoc.
>
> On http://java.sun.com/docs/books/tutorial/essential/io/legacy.html in
> "Mapping java.io.File Functionality to java.nio.file"-table I find:
> |File.delete| --> |Path.delete| or |Path.delete(boolean)
>
> |But there is no expression for delete(boolean) in current
> implementation of Path.
Thanks. I think Sharon Zakhour (the tech writer that developed this
tutorial) has already fixed this one and a couple of other issues. They
just aren't pushed to java.sun.com yet.
-Alan.
More information about the nio-discuss
mailing list