package test;
import java.io.File;
public class DeleteFile {
public static void main(String[] args){
File file = new File("D:\\test");
new DeleteFile().deleteFile(file);
}
private void deleteFile(File file){
if(file.exists()){
if(file.isFile()){
file.delete();
}else if(file.isDirectory()){
File files[] = file.listFiles();
for(int i=0;i<files.length;i++){
this.deleteFile(files[i]);
}
}
file.delete();
}else{
System.out.println("刪除的文件夾不存在"+'\n');
}
}
}