/** * 删除文件夹 * @param floderPath 文件夹地址 */ public static void delFloder(String floderPath) { try { delFile(floderPath); //删除文件 java.io.File myFilePath = new java.io.File(floderPath); myFilePath.delete(); //删除空文件夹 } catch (Exception e) { e.printStackTrace(); } }
/** * 删除文件 * @param path 文件地址 */ public static void delFile(String path) { File file = new File(path); String[] fileName = file.list(); File temp = null; for (int i = 0; i < fileName.length; i++) { if (path.endsWith(File.separator)) { temp = new File(path + fileName[i]); } else { temp = new File(path + File.separator + fileName[i]); } if (temp.isFile()) { temp.delete(); } if (temp.isDirectory()) { delFile(path + "/" + fileName[i]); delFloder(path + "/" + fileName[i]); } } }
}