How do I open a file or folder from a java application?

How can we open a file or folder, as if we are opening it through a standard file browser / Finder / etc.

Author: ofitserov, 2011-01-24

1 answers

You should pay attention to the Desktop API. Here is a article detailing it.

Initialization:

Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
    desktop = Desktop.getDesktop();
}

Opening a file:

try {
    desktop.open(new File(fileName));
} catch (IOException ioe) {
    ioe.printStackTrace();
}
 10
Author: ofitserov, 2017-11-18 22:02:51