Api Desktop.isDesktopSupported在windows中返回null

Api Desktop.isDesktopSupported在windows中返回null,api,desktop,Api,Desktop,我有以下代码 desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; url = new URL("http://www.facebook.com"); if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try { desktop.browse(u

我有以下代码

    desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    url = new URL("http://www.facebook.com");
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
            desktop.browse(url.toURI());
        } catch (Exception e) {
            e.printStackTrace();
        }
Windows 7的桌面正在返回null。有人能建议怎么做吗?

来自:

测试当前平台是否支持此类。如果支持,请使用getDesktop()检索实例

返回:
true
如果当前平台支持该类<代码>错误否则

简而言之: Windows 7不支持此类

  • 另见:

  • 另见:


不确定它是否适用于Windows 7(它适用于我),但无论如何,桌面都可能返回假阴性。我有一个很好的解决方法,我能找到的唯一方法就是使用java.lang.Runtime以艰难的方式打开系统浏览器

对于windows,您的代码将是

 Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler " + url);

可以找到一个非常好的完全工作的代码,它也涵盖了OSX和Linux

对不起,我不知道这个问题的解决方法
 Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler " + url);