Stream API 遍历文件

Stream API 遍历文件

    @Test
    public void test2() throws IOException {
        Stream<Path> list = Files.list(Paths.get("C:\\Users\\82341\\Desktop\\ps"));
        list.forEach(this::list);
    }
    public void list(Path path) {
        if (Files.isDirectory(path)) {
            try {
                Files.list(path).forEach(System.out::println);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else{
            System.out.println(path);
        }
    }
posted @ 2020-05-22 16:46  CyberPelican  阅读(178)  评论(0编辑  收藏  举报