亲测可用,若有疑问请私信
/**
* 删除指定目录下的文件及目录
*/
public static deleteFolderFile(String filePath, boolean deleteThisPath){
if (!TextUtils.isEmpty(filePath)) {
File file = new File(filePath);
if (file.isDirectory()) {
File files[] = file.listFiles();
for (int i = 0; i < files.length; i++) {
deleteFolderFile(files[i].getAbsolutePath(), true);
}
}
if (deleteThisPath) {
if (!file.isDirectory()) {
file.delete();
}else {
if (file.listFiles().length == 0) {
file.delete();
}
}
}
}
}