Michał Ziober
Michał Ziober

Reputation: 38635

How to open file without extension

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?

Upvotes: 0

Views: 2132

Answers (2)

Ivaylo Mihaylov
Ivaylo Mihaylov

Reputation: 87

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

Upvotes: 0

Zed
Zed

Reputation: 57648

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

Upvotes: 2

Related Questions