Here you can find the source of deletefile(String delpath)
public static boolean deletefile(String delpath) throws FileNotFoundException, IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; public class Main { public static boolean deletefile(String delpath) throws FileNotFoundException, IOException { try {/* w w w . j a v a2s .c om*/ File file = new File(delpath); if (!file.isDirectory()) { file.delete(); } else if (file.isDirectory()) { String[] filelist = file.list(); for (int i = 0; i < filelist.length; i++) { File delfile = new File(delpath + "/" + filelist[i]); if (!delfile.isDirectory()) { delfile.delete(); } else if (delfile.isDirectory()) { deletefile(delpath + "" + filelist[i]); } } file.delete(); } } catch (FileNotFoundException e) { e.printStackTrace(); } return true; } }