code: public static boolean delete(File file) {
          boolean result = true;
  
          if (file == null) {
              return false;
          }
          if (file.exists()) {
              if (file.isDirectory()) {
                  // 1. delete content of directory:
                  File[] children = file.listFiles();
                  for (File child : children) { //for each file:
                      result = result && delete(child);
                  }//next file
              }
              result = result && file.delete();
          } //else: input directory does not exist or is not a directory
          return result;
      }
docs: Delete a File.
  
  @param file
  the File to delete.
  @return <code>true</code> if the operation was successful;
  <code>false</code> otherwise (which includes a null input).