Java - Desktop.getDesktop().browse(URI) 受支持,但不打开文档(citrix 问题?)

Jay*_*yan 6 java windows 64-bit citrix xenapp

(我不确定这是否是提出此问题的正确位置。请移至合适的站点)

我有一个问题,显示在下面的代码中。它不适用于装有 CITRIX Xen App 6- 的机器(windows 2008)。没有错误,只是浏览器没有启动。在我的桌面(一个 windows7 盒子)上,它可以工作。

package trials;

import java.awt.*;
import java.io.File;
import java.io.IOException;


public class Launch {

    public static void main(String[] args) throws IOException {
        if (args.length < 1) {
            System.out.println("argument filepath expected");
            return;
        }

        final boolean browseSupported = Desktop.getDesktop().isSupported(Desktop.Action.BROWSE);
        if ( !browseSupported) {
            System.out.println("Browse not supported");
            return;
        }

        final String filename = args[0];
        final File file = new File(filename);
        if (file.exists()) {
            Desktop.getDesktop().browse(file.toURI());
        } else {
            System.out.println(file.getAbsolutePath() + " does not exist");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试按照以下答案中的建议使用“打开”。这没用。问题缩小到 64 位版本的 Java(Oracle 1.6.0_25)

小智 5

要打开本地文件,您必须使用Desktop().open()notDesktop.browse()


小智 2

我认为造成这种现象的原因是awt包使用了win2008不支持的系统调用。但这是一个提示。

我认为你应该尝试其他解决方案:

if (file.exists()) {
        Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file.toURI());
    } else {
        System.out.println(file.getAbsolutePath() + " does not exist");
    }
Run Code Online (Sandbox Code Playgroud)

  • 这不适用于非 Windows 系统,因此我建议不要使用它。 (3认同)