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

发布于 2024-12-01 15:55:07 字数 1042 浏览 2 评论 0原文

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

我遇到了以下代码中显示的问题。它不适用于具有 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");
        }
    }
}

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

(I am not sure if this is the correct place to ask this question. Please move to suitable site)

I have a problem that is shown in below code. It does not work on machine (windows 2008) that has CITRIX Xen App 6-. There is no error, just that browser does not get launched. On my desktop (a windows7 box), it works.

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");
        }
    }
}

I tried to use "open" as suggested in following answers. It did not work. The problem is narrowed down to 64bit version of Java(Oracle 1.6.0_25)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

世界和平 2024-12-08 15:55:07

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

To open a local file you have to use Desktop().open() not Desktop.browse()

流心雨 2024-12-08 15:55:07

我在 Windows XP 上测试过的另一个简单的可能性:

org.eclipse.swt.program.Program.launch("file://" + filename);

Another easy possibility that I have tested on Windows XP:

org.eclipse.swt.program.Program.launch("file://" + filename);
想你的星星会说话 2024-12-08 15:55:07

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

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

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

I think the cause of this symptom is the awt package what uses a system call what the win2008 not supports. But it's a tip.

I think You should try an other solution for this:

if (file.exists()) {
        Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file.toURI());
    } else {
        System.out.println(file.getAbsolutePath() + " does not exist");
    }
猫卆 2024-12-08 15:55:07

Desktop.browse() 启动本地 Web 浏览器。在 Windows 上,Web 浏览器可能会将其踢出到默认 shell,从而打开该文件。

我的猜测是 Citrix 系统上的浏览器无法/无法正确处理该文件,因此不会将其传递给 shell。

无论如何,如果您要打开文件(而不是 URL),那么您似乎需要使用 Destop.open() 来代替。

Desktop.browse() launches the local web browser. On Windows, the web browser is probably kicking it out to the default shell, which opens the file.

My guess is that the browser on the Citrix system cannot/doesn't handle the file properly, thus not passing it to the shell.

In any case, it appears that if you are opening a file (and not a URL), then you want to use Destop.open() instead.

摇划花蜜的午后 2024-12-08 15:55:07

我在桌面级也遇到了类似的问题。

如果文件无法打开但引发异常,请尝试编辑它。我在处理某些图像文件和窗口时遇到了麻烦,因为除了编辑器之外没有关联的程序。

I had a similar problem with the Desktop-class.

If the file will not open but throws an exception, try to edit it. I had trouble with some image files and windows, because there was no associated program but an editor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文