代码
import java.io.File; publicclass FileDeleteDemo {publicstaticvoidmain(String[] args) {// 封装目录 File srcFolder =new File("Folder");// 递归实现 deleteFolder(srcFolder); }privatestaticvoiddeleteFolder(File srcFolder) {// TODO Auto-generated method stub// 获取该目录下所有文件和文件夹的File数组 File[] fileArray = srcFolder.listFiles();// 如果fileArray数组不为空才能使用增强forif (fileArray !=null) {// 遍历该数组获得每一个File对象for (File file : fileArray) {// 判断该file对象是否是文件夹if (file.isDirectory()) { deleteFolder(file); }else { System.out.println(file.getName() +"---" + file.delete()); } } System.out .println(srcFolder.getName() +"---" + srcFolder.delete()); } } }