方式一:
Desktop.getDesktop().browse(new URI(manualUrl));
在linux环境bug
方式二:
转载自:https://stackoverflow.com/questions/5226212/how-to-open-the-default-webbrowser-using-java/28807079#28807079
Windows: Runtime rt = Runtime.getRuntime(); String url = "http://stackoverflow.com"; rt.exec("rundll32 url.dll,FileProtocolHandler " + url); Mac Runtime rt = Runtime.getRuntime(); String url = "http://stackoverflow.com"; rt.exec("open " + url); Linux: Runtime rt = Runtime.getRuntime(); String url = "http://stackoverflow.com"; String[] browsers = { "epiphany", "firefox", "mozilla", "konqueror", "netscape", "opera", "links", "lynx" }; StringBuffer cmd = new StringBuffer(); for (int i = 0; i < browsers.length; i++) if(i == 0) cmd.append(String.format( "%s \"%s\"", browsers[i], url); else cmd.append(String.format(" || %s \"%s\"", browsers[i], url); // If the first didn't work, try the next browser and so on rt.exec(new String[] { "sh", "-c", cmd.toString() }); If you want to have multiplatform application, you need to add operation system checking(for example): String os = System.getProperty("os.name").toLowerCase(); Windows: os.indexOf("win") >= 0 Mac: os.indexOf("mac") >= 0 Linux: os.indexOf("nix") >=0 || os.indexOf("nux") >=0