using URL#toString worked fine for me. Seems the easiest. When having a File someFile then one can do someFile.toURI().toURL() to get it escaped correctly. I know that an URL pointing to resources inside a jar (jar:file://) does not work for the 'start' command. Also apparently the 'start' command knows how to handle URLs, but when using some other program instead of 'start' (e.g. C:\someProgram.exe) the behavior may be different.
using URL#toString worked
using URL#toString worked fine for me. Seems the easiest. When having a File someFile then one can do someFile.toURI().toURL() to get it escaped correctly. I know that an URL pointing to resources inside a jar (jar:file://) does not work for the 'start' command. Also apparently the 'start' command knows how to handle URLs, but when using some other program instead of 'start' (e.g. C:\someProgram.exe) the behavior may be different.
public static void startFileWithWindowsDefaultProgram(final URL url) { try { Runtime.getRuntime().exec( // String.format("cmd /C \"start %1s\"", url.toString()), // null, // null); } catch (final Exception e) { e.printStackTrace(); } } public static void main(final String[] args) throws Exception { startFileWithWindowsDefaultProgram(new File("C:\\Program Files\\AC3Filter\\pic\\email.gif") .toURI().toURL()); }