private static boolean doDeleteDir(File file,boolean recurse){
  if (file != null && file.exists()) {
    if (file.isFile() || !recurse) {
      return file.delete();
    }
    String[] fnames=file.list();
    File child=null;
    for (int i=0; i < fnames.length; i++) {
      child=new File(file,fnames[i]);
      if (!doDeleteDir(child,recurse)) {
        return false;
      }
    }
    return file.delete();
  }
  return true;
}

private static boolean doDeleteDir ( File file , boolean recurse ) { if ( file != null && file . exists ( ) ) { if ( file . isFile ( ) || ! recurse ) { return file . delete ( ) ; } String [ ] fnames = file . list ( ) ; File child = null ; for ( int i = 0 ; i < fnames . length ; i ++ ) { child = new File ( file , fnames [ i ] ) ; if ( ! doDeleteDir ( child , recurse ) ) { return false ; } } return file . delete ( ) ; } return true ; }
implementation of the file deletion
