为什么 Desktop.Open() 在安装 MagicISO 时不起作用

2024-02-17

这是我的代码

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(从这个 Java 错误 https://bugs.java.com/bugdatabase/view_bug?bug_id=6546085)将使此代码不起作用。但为什么? MagicISO具体是做什么的?我可以阻止它发生或解决它吗?

更糟糕的是,这段代码不会抛出任何异常。它只是静静地呆在那里。这真的让我抓狂。


引用第二个答案从 Java 启动文件 https://stackoverflow.com/questions/847838/launch-file-from-java:

您可以通过以下方式启动应用程序Runtime class:

On Mac,

Runtime.getRuntime().exec(new String[] {"open", pathToFile});

在 Windows 上,

Runtime.getRuntime().exec(new String[] {"cmd.exe", "/C", pathToFile});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么 Desktop.Open() 在安装 MagicISO 时不起作用 的相关文章

随机推荐