查找目录下的所有路径

拉基姆

我需要做的就是扫描目录(可能包含子目录)并获取其中包含的所有路径的列表。

编辑:更改整个问题,使其更具体!

马辛克

我的尝试是:

    try {
        List<Path> pathsInDir = new ArrayList<>();

        // Dir to scan
        DirectoryStream<Path> newDirectoryStream = Files.newDirectoryStream(Paths.get("."));

        for(Path path : newDirectoryStream) {
            if(Files.isDirectory(path)) {
                pathsInDir.add(path);
                // recursive call to scan sub dir
            } else {
                // handle files.
            }
        }
    } catch (IOException e) {
        // TODO please handle the exception.
        e.printStackTrace();
    }

您可以使用java.nio.file.Path的方法来比较目录名称。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章