Java - 支持 Desktop.getDesktop().browse(URI),但无法打开文档(citrix 问题?)
(我不确定这是否是提出此问题的正确位置。请移至合适的站点)
我遇到了以下代码中显示的问题。它不适用于具有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
要打开本地文件,您必须使用
Desktop().open()
而不是Desktop.browse()
To open a local file you have to use
Desktop().open()
notDesktop.browse()
我在 Windows XP 上测试过的另一个简单的可能性:
Another easy possibility that I have tested on Windows XP:
我认为造成这种现象的原因是awt包使用了win2008不支持的系统调用。但这是一个提示。
我认为你应该尝试其他解决方案:
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:
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.我在桌面级也遇到了类似的问题。
如果文件无法打开但引发异常,请尝试编辑它。我在处理某些图像文件和窗口时遇到了麻烦,因为除了编辑器之外没有关联的程序。
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.