Java 读取目录下的全部文件和文件夹

/**
* @Author:
* @Description:获取某个目录下所有直接下级文件,不包括目录下的子目录的下的文件,所以不用递归获取
* @Date:
*/
public static List<String> getFiles(String path) {
    List<String> files = new ArrayList<String>();
    File file = new File(path);
    File[] tempList = file.listFiles();

    for (int i = 0; i < tempList.length; i++) {
        if (tempList[i].isFile()) {
            files.add(tempList[i].toString());
            //文件名,不包含路径
            //String fileName = tempList[i].getName();
        }
        if (tempList[i].isDirectory()) {
            //这里就不递归了,
        }
    }
    return files;
}

转载自: https://www.cnblogs.com/shaosks/p/9625878.html


原文地址:https://www.cnblogs.com/betterwgo/p/13353953.html