0

Is anybody aware of the difference between these two FileVisitResult? Directly from this oracle tutorial:

SKIP_SUBTREE – When preVisitDirectory returns this value, the specified directory and its subdirectories are skipped. This branch is "pruned out" of the tree.

SKIP_SIBLINGS – When preVisitDirectory returns this value, the specified directory is not visited, postVisitDirectory is not invoked, and no further unvisited siblings are visited. If returned from the postVisitDirectory method, no further siblings are visited. Essentially, nothing further happens in the specified directory.

4

1 回答 1

1

似乎您回答了自己的问题,但如果 oracle 教程的解释没有消除您的所有疑问,这就是javadoc所说的:

SKIP_SUBTREE

继续而不访问此目录中的条目。此结果仅在从 preVisitDirectory 方法返回时才有意义;否则此结果类型与返回 CONTINUE 相同。

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;
}

这里还有一个关于enums的教程。

于 2013-05-14T16:40:37.633 回答