code: public static void deleteDirContents(File dir) {
          if (!dir.isDirectory() || !dir.exists()) {
              throw new IllegalArgumentException(dir.getAbsolutePath()
                      + " is not a directory or does not exist.");
          }
          String[] children = dir.list();
          for (int i = 0; i < children.length; i++) {
              File f = new File(dir, children[i]);
              if (f.isDirectory()) {
                  deleteDirContents(f);
              }
              f.delete();
          }
      }
docs: Deletes the contents of a directory, including subdirectories.
  
  @param dir
  The directory to be emptied.