code: private static void removeDirectory(File directory) throws IOException
    {
      // File.listFiles() may return null is file is not a directory - condition already tested before entering this
      // method
      for(File file : directory.listFiles()) {
        if(file.isDirectory()) {
          removeDirectory(file);
        }
        log.trace("Delete %s |%s|.", file.isDirectory() ? "empty directory" : "file", file);
        if(!file.delete()) {
          throw new IOException(String.format("Fail to delete %s |%s|.", file.isDirectory() ? "empty directory" : "file", file));
        }
      }
    }
docs: Utility method invoked recursively to remove directory files. This method traverses <code>directory</code> files
  and remove them, one by one. If a child file is happen to be a directory this method invoked itself with child
  directory as parameter. After child directory is clean-up iteration continue removing child directory itself. Note
  that given <code>directory</code> is not removed.
  <p>
  On remove exception <code>directory</code> state is not defined, that is, some files may be removed while others
  may not.
  
  @param directory directory to remove files from.
  @throws IOException if remove operation fails.