利用Java打开浏览器访问特定网址
- - Linux - 操作系统 - ITeye博客已有 0 人发表留言,猛击->> 这里<<-参与讨论. —软件人才免语言低担保 赴美带薪读研.
public static void openURL(String url) { String os = System.getProperty("os.name"); // Linux if (os.indexOf("Linux") != -1) { try { String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" }; String browser = null; for (int count = 0; count < browsers.length && browser == null; count++) { if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0) { browser = browsers[count]; } } if (browser != null) { Runtime.getRuntime().exec(new String[] { browser, url }); } } catch (IOException e1) { e1.printStackTrace(); } catch (InterruptedException e2) { e2.printStackTrace(); } // Windows } else { String cmd = "rundll32 url.dll,FileProtocolHandler http://" + url; try { Runtime.getRuntime().exec(cmd); } catch (IOException e) { e.printStackTrace(); } } }