Bug in Files.copy() where the source Path is a directory... It _is_ a bug, right?

Francis Galiegue fgaliegue at gmail.com
Wed Dec 10 22:06:28 UTC 2014


On Wed, Dec 10, 2014 at 10:34 PM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> On 10/12/2014 19:48, Francis Galiegue wrote:
>
> :
>
> Yep, it only copied the directory entry and no files under it!
>
> Here's what the javadoc says:
>
> "If the file is a directory then it creates an empty directory in the target
> location (entries in the directory are not copied). This method can be used
> with the walkFileTree method to copy a directory and all entries in the
> directory, or an entire file-tree where required."
>

OK, so yet again an example of me only reading parts of the doc...

May I suggest that this part of the doc be emphasized?

> There have been requests over the years to add support for recursive copy,
> maybe a copyFileTree method but all suggestions to date didn't get to a
> consensus on how exceptions should be handled when only a subset of the file
> tree can be copied. Maybe some day.
>

Well, I have in the pipe to create a java7-fs-more package where I
will create a MoreFiles and MorePaths utility classes with recursive
copy/move features, path resolution across different filesystems
etc... I will announce it on this list when I have a first version of
it.

Before I do that however, I am still on some java.nio.file related
projects, so I'd appreciate comments on it:

* https://github.com/fge/java7-fs-base --> framework to implement new
FileSystems, with limitations, of course; not all of them are fully
documented;
* https://github.com/fge/java7-fs-dropbox --> a FileSystem
implementation over DropBox, based on -base;
* https://github.com/fge/java7-fs-box --> a FileSystem implementation
over box.com, also based on -base.

As to other existing java.nio.file FileSystem implmentations, I only
know of two:

* https://github.com/google/jimfs --> an in-memory FileSystem, by Google;
* https://github.com/fge/java7-fs-ftp --> meh, that was my first
attempt as a custom FileSystem and prompted me to create -base and
others; not yet rebased on -base.

In summary, I am very excited with this new API and it is now three
years old; as such I am quite surprised that its usage is still scarce
as of 2014.

Even in the latest JDK, for instance FileInputStream won't accept any
Path arguments; a ProcessBuilder won't allow to redirect to a Path,
only to a File. Is this on purpose?

-- 
Francis Galiegue, fgaliegue at gmail.com, https://github.com/fge
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Parsers in pure Java: https://github.com/parboiled1/grappa (redde
Caesaris: https://github.com/sirthias)


More information about the nio-dev mailing list