code: private void cleanDir(File dir) {
          File[] files = dir.listFiles();
          if (files != null && files.length > 0) {
              for (int i = 0; i < files.length; i++) {
                  File file = files[i];
                  // if file is a directory, first delete all the files inside, then delete the directory itself.
                  if (file.isDirectory()) {
                      cleanDir(file);
                  }
                  if (!file.delete()) {
                      throw new BuildException(MessageFormat.format(messages.getString("error.cannot.delete.file"), file.getAbsolutePath()));
                  }
              }
          }
      }
docs: Delete every file/folder inside the dir directory.
  @param dir The directory to be cleaned.