递归遍历文件目录及子目录文件

package com.lzz.util;

import java.io.File;
import java.util.List;

/**
 * @author lzz
 * @description:
 * @date 2018/8/2 19:21
 */
public class FilePath {
    private static List<String> getAllFilePaths(File filePath, List<String> filePaths){
        File[] files = filePath.listFiles();
        if(files == null){
            return filePaths;
        }
        for(File f:files){
            if(f.isDirectory()){
                //是否需要把当前文件夹加入路径,如果只需要找到文件,就不要加入
                //filePaths.add(f.getPath());
                getAllFilePaths(f,filePaths);
            }else{
                filePaths.add(f.getPath());
            }
        }
        return filePaths;
    }
}

猜你喜欢

转载自blog.csdn.net/m0_37179470/article/details/81393338