java 递归删除指定文件夹下的所有内容
程序员文章站
2022-05-20 10:38:02
...
/**
*删除文件夹下的文件
*
*/
public static void delFiles(String filePath){
File file = new File(filePath);
if(!file.exists()){
return;
}
String[] list = file.list();
File temp = null;
String path = null;
for (String item:list) {
path = filePath + File.separator + item;
temp = new File(path);
if(temp.isFile()){
temp.delete();
continue;
}
if(temp.isDirectory()) {
delFiles(path);
new File(path).delete();
continue;
}
}
}
public static void main(String[] args){
String filePath = "*********";
delFiles(filePath);
}