Rollerball
Rollerball

Reputation: 13118

Files.move(Path, Path) in Java

By reading this tutorial, I have come across this part which is not quite clear to me.

Empty directories can be moved. If the directory is not empty, the move is allowed when the directory can be moved without moving the contents of that directory.

I obviously thoroughly understand that the empty directories can be moved. However the second part of the quote seems to me a little confusing. Anyone able to express the same concept in other words? Thanks in advance.

Upvotes: 1

Views: 406

Answers (2)

Puce
Puce

Reputation: 38152

Have a look at the Javadoc linked in the tutorial:

http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#move%28java.nio.file.Path,%20java.nio.file.Path,%20java.nio.file.CopyOption...%29

[...] For example, renaming a directory on the same FileStore will usually not require moving the entries in the directory. When moving a directory requires that its entries be moved then this method fails (by throwing an IOException). To move a file tree may involve copying rather than moving directories and this can be done using the copy method in conjunction with the Files.walkFileTree utility method.

Upvotes: 1

LionC
LionC

Reputation: 3106

On UNIX systems, moving a directory within the same partition generally consists of renaming the directory. In that situation, this method works even when the directory contains files.

This is actually the next sentence in the link you posted, that provides an example for when it is possible to use move even if the directory is not empty.

Upvotes: 4

Related Questions