SKIP_SIBLINGS和SKIP_SUBTREE之间的区别

时间:2013-05-14 16:29:54

标签: java file io nio

有人知道这两个FileVisitResult之间的区别吗? 直接来自this oracle教程:

  

SKIP_SUBTREE - 当preVisitDirectory返回此值时,   指定的目录及其子目录被跳过。这个分支是   树被“修剪掉”。

     

SKIP_SIBLINGS - 当preVisitDirectory返回此值时,   未访问指定的目录,不调用postVisitDirectory,   并且没有进一步访问未访问过的兄弟姐妹。如果从   postVisitDirectory方法,不再访问兄弟姐妹。   基本上,在指定的目录中没有任何进一步的发生。

1 个答案:

答案 0 :(得分: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的教程。