public static boolean cleanDir(String directory) throws IOException {
  String[] files=ls(directory);
  boolean clean=true;
  if (files != null) {
    for (    String f : files) {
      String filename=directory + File.separator + f;
      File file=new File(filename);
      if (file.isDirectory())       clean=cleanDir(filename) && file.delete();
 else       clean=file.delete();
    }
  }
  return clean;
}

public static boolean cleanDir ( String directory ) throws IOException { String [ ] files = ls ( directory ) ; boolean clean = true ; if ( files != null ) { for ( String f : files ) { String filename = directory + File . separator + f ; File file = new File ( filename ) ; if ( file . isDirectory ( ) ) clean = cleanDir ( filename ) && file . delete ( ) ; else clean = file . delete ( ) ; } } return clean ; }
empty a directory without deleting it
