有人知道这两个FileVisitResult之间的区别吗?直接来自这甲骨文教程:
SKIP_SUBTREE -当preVisitDirectory返回此值时,将跳过指定的目录及其子目录。这枝树枝被“修剪掉”了。 SKIP_SIBLINGS -当preVisitDirectory返回此值时,指定的目录不会被访问,postVisitDirectory不会被调用,也不会再访问未访问的兄弟姐妹。如果从postVisitDirectory方法返回,则不会访问其他兄弟姐妹。本质上,在指定的目录中不再发生任何其他事情。
发布于 2013-05-14 16:40:37
你似乎回答了自己的问题,但如果甲骨文教程中的解释没有消除你的所有疑虑,那么javadoc就是这么说的:
SKIP_SUBTREE
继续,而不访问该目录中的条目。只有当从preVisitDirectory方法返回时,此结果才有意义;否则,此结果类型与返回继续相同。
SKIP_SIBLINGS
继续,而不访问此文件或目录的同级。如果从preVisitDirectory方法返回,那么目录中的条目也会被跳过,并且不会调用postVisitDirectory方法。
这是FileVisitResult的代码
public enum FileVisitResult {
/**
* Continue. When returned from a {@link FileVisitor#preVisitDirectory
* preVisitDirectory} method then the entries in the directory should also
* be visited.
*/
CONTINUE,
/**
* Terminate.
*/
TERMINATE,
/**
* Continue without visiting the entries in this directory. This result
* is only meaningful when returned from the {@link
* FileVisitor#preVisitDirectory preVisitDirectory} method; otherwise
* this result type is the same as returning {@link #CONTINUE}.
*/
SKIP_SUBTREE,
/**
* Continue without visiting the <em>siblings</em> of this file or directory.
* If returned from the {@link FileVisitor#preVisitDirectory
* preVisitDirectory} method then the entries in the directory are also
* skipped and the {@link FileVisitor#postVisitDirectory postVisitDirectory}
* method is not invoked.
*/
SKIP_SIBLINGS;
}这里还有一个关于枚举的教程。
https://stackoverflow.com/questions/16548333
复制相似问题