public static boolean deleteDir(File dir)
{
if (dir.isDirectory())
{
// get the names of the child files and directories into an array of String
String[] children = dir.list();

// for each child file or directory
for (int i = 0; i < children.length; i++)
{
// recursively delete
deleteDir(new File(dir, children[i]));
}
}

return dir.delete();
}