欢迎访问我的个人网站==》 jiashubing.cn

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);
            }
        }
    }
}

 

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

posted @ 2017-09-01 15:38  贾树丙  阅读(1265)  评论(0编辑  收藏  举报