读取目录下的所有文件

采用递归的方式,逐层读取目录下的文件   

public void getFile(String path, List<String> fileList) {
        File file = new File(path);
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            if (files != null) {
                for (File subFile : files) {
                    getFile(subFile.getPath(), fileList);
                }
            }
        } else {
            fileList.add(file.getAbsolutePath());
        }
    }

posted @ 2020-02-13 21:44  tulip20  阅读(57)  评论(0编辑  收藏  举报