Why Desktop.Open() doesn't work with MagicISO being installed

China☆狼群 提交于 2019-12-12 11:06:27

问题


Here's my code

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

I know that installing MagicISO (got it from this Java bug) will make this code doesn't work. But why? What does MagicISO specificially do? Can I prevent it to happen or work it around?

Even worse, this code doesn't throw any exception. It just stays silent there. This really really makes me crazy.


回答1:


Quoting from the 2nd answer for Launch file from Java:

You can launch the application via the Runtime class:

On Mac,

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

On Windows,

Runtime.getRuntime().exec(new String[] {"cmd.exe", "/C", pathToFile});



回答2:


Unfortunately I have not heard of this issue before, but you could always add a manual check in the beginning of your code to see if MagicISO has been installed and if so leave a useful message along the lines of "this program cannot be run due to..."




回答3:


Well if I had to take a guess, MagicISO modifies the registry or something in some way which prevents Java from knowing what program to launch the file with. If you're looking for an alternative solution, see Adel Boutros's answer



来源:https://stackoverflow.com/questions/11774247/why-desktop-open-doesnt-work-with-magiciso-being-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!