Java递归删除目录下所有的txt文件

public static void delAllFile(File path) {
    if (!path.exists() || !path.isDirectory()) { //不是目录
        return ;
    }
    String[] tmpList = path.list();
    if (tmpList != null) {
        for (String aTempList : tmpList) {
            File tmpFile = new File(path, aTempList);
            if (tmpFile.isFile() && tmpFile.getName().endsWith(".txt")) {
                tmpFile.delete();
            } else if (tmpFile.isDirectory()) {
                delAllFile(tmpFile);
            }
        }
    }
}

原创文章,欢迎转载,转载请注明出处!

原文地址:https://www.cnblogs.com/acm-bingzi/p/deleteFile.html