直接上代码
public static void deleteFile(String filePath) {
File file = new File(filePath);
if (file.isFile()){//文件
file.delete();
}else {//文件夹
String[] childFilePath = file.list();//获取文件夹下所有文件相对路径
if(childFilePath!=null&&childFilePath.length!=0) {
for (String path : childFilePath) {
deleteFile(file.getAbsoluteFile() + "/" + path);//递归,对每个都进行判断
}
}
file.delete();
}
}