Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 打开不在Mac OS上工作的浏览器链接_Java - Fatal编程技术网

Java 打开不在Mac OS上工作的浏览器链接

Java 打开不在Mac OS上工作的浏览器链接,java,Java,单击一个按钮,我希望应用程序打开一个URL。 因此,我正在这样做: Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; System.out.println("Hey "+desktop); if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try {

单击一个按钮,我希望应用程序打开一个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()
返回false。我使用的是Mac OS X 10.7.5。有其他选择吗?

在Mac上,这就可以了。感谢:


在Mac上,这就完成了任务。感谢:


对我来说很好。OSX 10.7.5,构建11G63b。Hmmm不在我的组件上。这是不可靠的,我得看看其他的作品。OSX 10.7.5,构建11G63b。Hmmm不在我的组件上。它不可靠,将不得不寻找替代品
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
 }
}