public static void deleteDirectory(File dir) throws IOException {
  if (!dir.isDirectory()) {
    throw new IllegalArgumentException(dir.getPath() + " should always be a directory!");
  }
  String[] children=dir.list();
  for (  String childname : children) {
    File child=new File(dir,childname);
    if (child.isDirectory()) {
      deleteDirectory(child);
      if (!child.delete()) {
        throw new IOException("Failed to delete file : " + child.getPath());
      }
    }
 else {
      if (!child.delete()) {
        throw new IOException("Failed to delete file : " + child.getPath());
      }
    }
  }
  if (!dir.delete()) {
    throw new IOException("Failed to delete directory : " + dir.getPath());
  }
}

public static void deleteDirectory ( File dir ) throws IOException { if ( ! dir . isDirectory ( ) ) { throw new IllegalArgumentException ( dir . getPath ( ) + " should always be a directory!" ) ; } String [ ] children = dir . list ( ) ; for ( String childname : children ) { File child = new File ( dir , childname ) ; if ( child . isDirectory ( ) ) { deleteDirectory ( child ) ; if ( ! child . delete ( ) ) { throw new IOException ( "Failed to delete file : " + child . getPath ( ) ) ; } } else { if ( ! child . delete ( ) ) { throw new IOException ( "Failed to delete file : " + child . getPath ( ) ) ; } } } if ( ! dir . delete ( ) ) { throw new IOException ( "Failed to delete directory : " + dir . getPath ( ) ) ; } }
delete a directory recursively
