zoukankan      html  css  js  c++  java
  • 遍历文件夹

    使用Files类的newDirectoryStream方法完成这一功能

    Path path=Paths.get("d:/test");
    try {
    DirectoryStream<Path> children=Files.newDirectoryStream(path);
    for(Path child:children){
    System.out.println(child);
    }
    } catch (IOException e) {
    System.err.println(e.toString());
    }

    Files提供了一个walkFileTree方法,可以用于遍历整个文件夹,并且针对每个文件可以进行特定的处理工作。

    public static Path walkFileTree(Path start,
    FileVisitor<? super Path> visitor) throws IOException
    FileVisitor是一个接口,它定义了四个方法:1)preVisitDirectory :在访问文件夹前调用

    2)postVisitDirectory:在访问文件夹后调用

    3)visitFile:在访问文件时调用

    4)visitFileFailed:当指定文件不可访问时调用

  • 相关阅读:
    Windsor
    .net 常见异常及其翻译
    nginx
    数据库访问层封装
    web api HttpConfiguration
    ENode, 领域模型,DDD
    缓存 Redis
    win7 快捷键
    visual studio 快捷键
    c# 正则表达式
  • 原文地址:https://www.cnblogs.com/lkwkk/p/14203950.html
Copyright © 2011-2022 走看看