Java tutorial
//package com.java2s; import java.io.File; public class Main { public static void delDir(File dir) { try { if (dir != null) { delAllFiles(dir); dir.delete(); } } catch (Exception e) { } } public static void delDir(String dirFullName) { delDir(new File(dirFullName)); } public static void delAllFiles(File dir) { if (!dir.exists() || !dir.isDirectory()) { return; } String dirFullName = dir.getAbsolutePath(); String[] fileList = dir.list(); File tempFile = null; for (int i = 0; i < fileList.length; i++) { if (dirFullName.endsWith(File.separator)) { tempFile = new File(dirFullName + fileList[i]); } else { tempFile = new File(dirFullName + File.separator + fileList[i]); } if (tempFile.isFile()) { tempFile.delete(); } if (tempFile.isDirectory()) { delAllFiles(dirFullName + "/" + fileList[i]); delDir(dirFullName + "/" + fileList[i]); } } } public static void delAllFiles(String dirFullName) { delAllFiles(new File(dirFullName)); } }