删除文件夹以及文件夹下的文件

public  boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();
            //递归删除目录中的子目录下
            for (int i=0; i<children.length; i++) {
                File childFile = new File(dir, children[i]);
                boolean success = childFile.delete();
                if (!success) {
                    return false;
                }
            }
        }
        // 目录此时为空,可以删除
        return dir.delete();
    }

猜你喜欢

转载自www.cnblogs.com/moonlignt/p/9233827.html