Java 删除目录
import java.io.File; public class DelDir { public static void main(String[] args) { delDir(new File("/home/huanyu/Desktop/a")); //如果文件里还有内容,则递归删除 } public static boolean delDir(File dir){ if (dir.isDirectory()){ String[] children = dir.list(); for (int i=0; i<children.length;i++) { boolean success = delDir(new File(dir, children[i])); if (!success) return false; } } if (dir.delete()){ System.out.println("目录已删除!!!"); return true; }else { System.out.println("目录删除失败!!!!!"); } return false; } }