public static void deleteDirectory(final File dir,boolean checkForLinks){
  if (dir.isFile()) {
    throw new IllegalArgumentException("Directory " + dir.getName() + " must not be a file!");
  }
 else   if (checkForLinks && isLink(dir)) {
    throw new IllegalArgumentException("Directory " + dir.getName() + " doesn't exist or is a symbolic link or has a path name of type ./xyz or ../xyz !");
  }
  if (dir.exists()) {
    IOUtils.deleteDir(dir,checkForLinks);
  }
 else {
    throw new IllegalArgumentException("Directory " + dir.getName() + " doesn't exist!");
  }
}

public static void deleteDirectory ( final File dir , boolean checkForLinks ) { if ( dir . isFile ( ) ) { throw new IllegalArgumentException ( "Directory " + dir . getName ( ) + " must not be a file!" ) ; } else if ( checkForLinks && isLink ( dir ) ) { throw new IllegalArgumentException ( "Directory " + dir . getName ( ) + " doesn't exist or is a symbolic link or has a path name of type ./xyz or ../xyz !" ) ; } if ( dir . exists ( ) ) { IOUtils . deleteDir ( dir , checkForLinks ) ; } else { throw new IllegalArgumentException ( "Directory " + dir . getName ( ) + " doesn't exist!" ) ; } }
this method recursively deletes the directory and all its contents . this method will not follow symbolic links , i . e . if the directory or one of the sub - directories contains a symbolic link , it will not delete this link . thus the directory can then not be deleted , too .
