code: public static void deleteDirectoryRecursively(File dir) throws IOException {
          File[] files = dir.listFiles();
          if (files == null) {
              throw new IllegalArgumentException("not a directory: " + dir);
          }
          for (File file : files) {
              if (file.isDirectory()) {
                  deleteDirectoryRecursively(file);
              }
              if (!file.delete()) {
                  throw new IOException("failed to delete file: " + file);
              }
          }
      }
docs: recursively delete
  
  @param dir
  @throws java.io.IOException