应同学要求需要几个调用浏览器的java代码
这段代码需要jdk1.6版本以上支持
public static void main(String[] args) throws IOException, URISyntaxException {
String webSite = "http://www.baidu.com";
OpenBroswer(webSite);
}
public static void OpenBroswer(String webSite) throws URISyntaxException,
IOException {
Desktop desktop = Desktop.getDesktop();
if (Desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE)) {
URI uri = new URI(webSite);
desktop.browse(uri);
}
}
}
jdk1.5版以及之前需要用下面这段代码
注意这段代码仅支持windows下的
public static void main(String[] args) {
// String osName = System.getProperty("os.name");
String url = "http://www.baidu.com";
// if (osName.startsWith("Windows")) {
try {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//}
}