code: public static void openFile(final File file) throws IOException {
          // Check that the file is a file
          if (!file.isFile()) throw new IOException("Passed file is not a file.");
  
          // Check that the Desktop API is supported
          if (!Desktop.isDesktopSupported()) {
              throw new IllegalStateException("Desktop is not supported");
          }
  
          final Desktop desktop = Desktop.getDesktop();
  
          // Check that the open functionality is supported
          if (!desktop.isSupported(Desktop.Action.OPEN)) {
              throw new IllegalStateException("Desktop doesn't support the open action");
          }
  
          // Open the file
          desktop.open(file);
      }
docs: Opens a file using the OS default program for the file type, using the Java Desktop API.
  
  @param file The file to be opened.
  @throws IOException Thrown if there is an issue opening the file.
  @throws IllegalStateException Thrown if the Desktop API isn't supported.