1

单击按钮时,我希望应用程序打开一个 URL。所以我这样做:

Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    System.out.println("Hey "+desktop);
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
            desktop.browse(new URL("http://support.apple.com/kb/DL1572").toURI());
            System.out.println("here");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Desktop.isDesktopSupported()返回假。我在 Mac OS X 10.7.5 上。有什么选择吗?

4

1 回答 1

1

在 Mac 上,这可以完成工作。多亏了这个

private void openUrlInBrowser(String url)
{
 Runtime runtime = Runtime.getRuntime();
 String[] args = { "osascript", "-e", "open location \"" + url + "\"" };
 try
 {
  Process process = runtime.exec(args);
 }
 catch (IOException e)
 {
// do what you want with this
 }
}
于 2013-04-11T13:57:55.493 回答