Here you can find the source of deleteFile(String path)
public static void deleteFile(String path)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static void deleteFile(String path) { File file = new File(path); if (!file.exists()) { return; }//from www . j av a 2 s .com if (!file.isDirectory()) { if (file.isFile()) { file.delete(); } return; } String[] tempList = file.list(); String childFilePath = null; for (int i = 0; i < tempList.length; i++) { if (path.endsWith(File.separator)) { childFilePath = path + tempList[i]; } else { childFilePath = path + File.separator + tempList[i]; } File temp = new File(childFilePath); if (temp.isFile()) { temp.delete(); } else if (temp.isDirectory()) { deleteFile(childFilePath); } } file.delete(); } }