Java递归扫描文件路径

import java.io.File;

public class Test {
    
    public static int count = 0;
    
    public static void main(String[] args){
        String path = "G:/Document/HongDaXingYe/Project/oa/workflow/home/weaver/ecology/workflow/";
//        String path = "G:/Document/HongDaXingYe/Project/oa/workflow/home/weaver/ecology/workflow/mode/";
        File file = new File(path);
        File[] files = file.listFiles();
        getFiles(files);
        System.out.println(count);
    }
    
    public static void getFiles(File[] files){
        for(File file : files){
            count++;
            if(file.isDirectory()){
                getFiles(file.listFiles());
            }else{
                System.out.println("file path:" + file.getAbsolutePath());
            }
        }
    }
    
}

直接上代码,路径改成你们要的文件夹路径就好了.

posted @ 2018-08-02 17:22  ラピスラズリ(Dawn)  阅读(316)  评论(0编辑  收藏  举报