Search code examples
javabrowserdirectorywindows-explorer

cross platform way to explore the containing folder of a file



is there functionality in java to open the containing folder of a file across any platform. I can accomplish this in windows by running

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("explorer /select,c:\\sampleFile.txt");

You can open a file (if the Desktop api is supported) on any platform with java.awt.Desktop.getDesktop().open(file). Is there something similar to bring up a file manager?

Thanks.


Solution

  • What happens if you call getDesktop().open(file.getParentFile()) ?