Launching the Default Windows Application using a Java
Application
by Michael Thomas
(Tutorial Home Page)
This example launches the default application (Default
Browser) for a .html file on a computer running a Windows OS.
- The source - right click, then
choose "Save Target As" and save to your local. The open
with an Editor.
HTML file - this is the
file that the Java Application will open with the default browser.
- This example must be run as an application, not from a browser as an
applet. Also, this example only runs on Windows machines.
- Here is a code sample from the source file:
String strCmd = "";
String strWindowsCommand = "rundll32 url.dll,FileProtocolHandler" + " ";
strCmd = strWindowsCommand + "MyLaunchDefaultBrowserExample.html";
try {
Process p = Runtime.getRuntime().exec(strCmd);
} catch ( Exception eExec ) {
System.out.println( eExec.toString() );
}