public static boolean deltree(File directory){
  if (directory == null || !directory.exists()) {
    return true;
  }
  boolean result=true;
  if (directory.isFile()) {
    result=directory.delete();
  }
 else {
    File[] list=directory.listFiles();
    for (int i=list.length; i-- > 0; ) {
      if (!deltree(list[i])) {
        result=false;
      }
    }
    if (!directory.delete()) {
      result=false;
    }
  }
  return result;
}

public static boolean deltree ( File directory ) { if ( directory == null || ! directory . exists ( ) ) { return true ; } boolean result = true ; if ( directory . isFile ( ) ) { result = directory . delete ( ) ; } else { File [ ] list = directory . listFiles ( ) ; for ( int i = list . length ; i -- > 0 ; ) { if ( ! deltree ( list [ i ] ) ) { result = false ; } } if ( ! directory . delete ( ) ) { result = false ; } } return result ; }
deletes the given file and everything under it .
