Java 为什么Desktop.Open()不';t安装MagicISO后无法工作
这是我的密码Java 为什么Desktop.Open()不';t安装MagicISO后无法工作,java,awt,desktop,shellexecute,Java,Awt,Desktop,Shellexecute,这是我的密码 if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { try { desktop.open(file.getCanonicalFile()); } catch (Exception ex) { ex.printStackTrace();
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.OPEN)) {
try {
desktop.open(file.getCanonicalFile());
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
System.out.println("Desktop open action is not supported");
}
} else {
System.out.println("Desktop is not supported");
}
我知道安装MagicISO(从中获得)会使此代码无法工作。但是为什么呢?MagicISO具体做什么?我可以防止它发生或解决它吗
更糟糕的是,此代码不会引发任何异常。它只是在那里保持沉默。这真的让我发疯。引用第二个答案: 您可以通过
运行时
类启动应用程序:
在Mac上
Runtime.getRuntime().exec(new String[] {"open", pathToFile});
在窗户上
Runtime.getRuntime().exec(new String[] {"cmd.exe", "/C", pathToFile});
不幸的是,我以前没有听说过这个问题,但您可以在代码的开头添加一个手动检查,查看是否安装了MagicISO,如果是,请留下一条有用的消息,大意是“由于…”而无法运行此程序。如果我不得不猜测,MagicISO以某种方式修改注册表或其他东西,从而阻止Java知道使用哪个程序启动文件。如果您正在寻找替代解决方案,请参阅Adel Boutros的答案难道您不能卸载MagicISO吗?PS:Java bug需要几十年才能修复,所以不要指望找到解决方法