扫描路径下的文件

static int count = 0 ;
public static void main(String[] args) throws IOException {
    String path = "D:\\logs";
    File file = new File(path);
    //io操作最好放到一个线程里去
    new Thread(()->{
        long start = System.currentTimeMillis();
        listAllFiles(file);
        long end = System.currentTimeMillis();
        System.out.println("共花费:" + (end - start) + "毫秒");
        System.out.println("有" + count + "个文件");
    }).start();
}

public static void listAllFiles(File file){
    if (file.isFile()){
        count++;
        System.out.println(file);
    } else {
        if (file.exists() && file.isDirectory()){
            File[] files = file.listFiles();
            for (File file1 : files){
                listAllFiles(file1);
            }
        }
    }
}