How to open file without extension

心不动则不痛 提交于 2019-12-11 16:49:33

问题


I would like to try open file without extension. When I try to open file without extension, then system show me "Open with" form. But when I am trying to open that file in side my application using method:

    private static void openFile(String fileName) throws IOException {
        if(Desktop.isDesktopSupported()) {
            Desktop desktop = Desktop.getDesktop();
            File file = new File(fileName);
            desktop.open(file);
        } else {
            Runtime.getRuntime().exec(String.format("cmd /c start %s", fileName));
        }
    }

system don't show this form. How to solve this?


回答1:


Desktop.open() launches the application associated with the extension of the file.




回答2:


try {
   Desktop desktop = Desktop.getDesktop();
   desktop.open(file);
}
catch (Exception ex) {
   Runtime.getRuntime().exec(String.format("cmd /c start %s", file));
}


来源:https://stackoverflow.com/questions/1310877/how-to-open-file-without-extension

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