public static boolean clearDir(File dir){
  if (!dir.isDirectory())   return false;
  File[] files=dir.listFiles();
  if (files == null || files.length == 0)   return true;
  boolean cleared=true;
  for (  File sub : files) {
    cleared&=delete(sub);
  }
  return cleared;
}

public static boolean clearDir ( File dir ) { if ( ! dir . isDirectory ( ) ) return false ; File [ ] files = dir . listFiles ( ) ; if ( files == null || files . length == 0 ) return true ; boolean cleared = true ; for ( File sub : files ) { cleared &= delete ( sub ) ; } return cleared ; }
deletes all sub - files and sub - directories in the given directory .
