I used the following code. In windows, you will open the Windows file open dialog box if no program is associated with the file type. If it does not start in windows, it returns to Desktop.open()
, which works if the file type is known to the system.
public static boolean openFile(File file){ try { if (System.getProperty("os.name").contains("Windows")) { Runtime.getRuntime().exec( "rundll32 SHELL32.DLL,ShellExec_RunDLL " + file.getAbsolutePath()); } else if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(file); } else { return false; } return true; } catch (final Exception e1) { System.err.println("Error opening file " + file, e1); return false; } }
source share