Javaからブラウザを起動する

単純に書くと


try {
//ブラウザを起動し、必要な URL を渡す
String browserName = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE";
String url = "C:\\index.html";
Runtime.getRuntime().exec(new String[ ] {browserName, url});

} catch (IOException ex) {
ex.printStackTrace();
}

htmlファイルに関連付けられているアプリケーションではなく、固定パスで指定する必要がある。
Java6では関連付けられているアプリケーションで起動ができるが、ローカルパスには対応していないらしい。

Windows限定としてcmdを呼び出してあげれば関連づいたアプリケシーョンで起動できるらしい。


try {
//関連づいたアプリケーションを起動し、必要な URL を渡す
String url = "C:\\index.html";
Runtime.getRuntime().exec(new String[ ] { "cmd " + url});

} catch (IOException ex) {
ex.printStackTrace();
}

参考URL
Javaアプリケーションからブラウザを開く -- BONNOH FRACTION 13
http://www.fraction.jp/log/archives/2006/01/65
Java SE 6 じゃじゃ馬ならし Desktop
http://www.javainthebox.net/laboratory/JavaSE6/desktop/desktop.html
教えて!goo javaでhtmlファイルを開く方法
http://oshiete1.goo.ne.jp/kotaeru.php3?q=1371589