简体   繁体   English

Java NIO存储路径列表

[英]Java NIO store list of Paths

geniuses. 天才。

I'm practicing Java NIO. 我正在练习Java NIO。

I'm trying to store list of files under different parent directories. 我正在尝试将文件列表存储在不同的父目录下。

So here is my code: 所以这是我的代码:

    ArrayList<Path> pathList = new ArrayList();
    Stream<Path> dirStream = Files.list(Paths.get("..."));
    dirStream.forEach((path) -> {
        pathList.add(Paths.get(path.toString(), "..."));
    });

I wonder if there are more fancy ways to do it. 我想知道是否还有其他花哨的方法可以做到这一点。

eg, store paths into a Stream<Path>. 例如,将路径存储到Stream <Path>中。

Thanks for your lesson! 感谢您的教训!

How about this 这个怎么样

ArrayList<Path> pathList = Files.list(Paths.get("..."))
                                .map(path -> path.resolve("..."))
                                .collect(Collectors.toList());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM