我有一大群用户无法从签名的小程序中启动本地创建的文件(PDF、Word 等)。在 Windows 资源管理器中双击文件会启动它,因此与启动应用程序的文件关联是已知的。技术支持在启用了 UAC 的机器上远程登录,发现加载小程序没有问题,并且可以毫无问题地启动本地文件。这让我觉得这个大群体有一个共同的本地环境。用户在 Windows XP(或 7,不确定)上运行 Java 1.6u31。java控制台中没有显示任何错误,也没有任何内容(所有传闻,因为我没有看到问题)。有关可能导致此行为的本地 PC 设置的任何建议?根据代码,问题似乎是支持 Desktop,但 Desktop.Action.OPEN 不支持。任何建议为什么?谢谢。
我正在使用以下内容来启动文件:
/*
//old way that would work for Windows prior to Java 1.6
//cmd = System.getenv("windir") +"\\system32\\"+"rundll32 SHELL32.DLL,ShellExec_RunDLL " + cmd;
//cmd = "open "+cmd; // Mac for PDF only?
//try{
// Runtime.getRuntime().exec(cmd);
//} catch (Exception e) {
// //handle error
//}
*/
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.OPEN)) {
try {
desktop.open(new File(file));
return;
} catch (IOException e) {
//Error launching the file
e.printStackTrace();
JOptionPane.showMessageDialog(theFrame,
"Unable to launch the file.",
"Document Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
} else {
//This OS cannot launch the file
JOptionPane.showMessageDialog(theFrame,
"This operating system is unable" +
"\nto launch external files" +
"\nfrom within this application.",
"Document Error", JOptionPane.ERROR_MESSAGE);
return;
}