code: private synchronized static void delete(File file) {
          // Check if file is directory
          if (file.isDirectory()) {
              // Get all files in the folder
              File[] files = file.listFiles();
  
              // Delete each file in the folder
              for (int i = 0; i < files.length; ++i) {
                  delete(files[i]);
              }
  
              // Delete the folder
              file.delete();
          } else {
              // Delete the file if it is not a folder
              file.delete();
          }
      }
docs: Delete file, recursively if needed
  
  @param file File/Directory to delete