From Java code, how do I open a specific folder (e.g. C:\Folder) in the platform's file explorer (e.g. Windows Explorer)? The examples are for Windows but I need a cross platform solution.
Asked
Active
Viewed 6.8k times
48
-
14I don't get why this is closed as not a real question. It seems very clear and useful to me. I do wish we could close some of the comments instead. – AnnTea Apr 23 '18 at 12:49
3 Answers
90
Quite simply:
Desktop.getDesktop().open(new File("C:\\folder"));
Note: java.awt.Desktop
was introduced in JDK 6.

Nathan
- 8,093
- 8
- 50
- 76

Buhake Sindi
- 87,898
- 29
- 167
- 228
-
1
-
This answer, as well as the other answers, do not work on my computer (Debian/KDE). Perhaps someone can come with solution that works on most platforms? (on my computer it should open the Dolphin file manager) – user42723 Feb 01 '18 at 00:17
-
19
Yes, you can do it with JDK 6 with the below code:
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
public class OpenFolder {
public static void main(String[] args) throws IOException {
Desktop desktop = Desktop.getDesktop();
File dirToOpen = null;
try {
dirToOpen = new File("c:\\folder");
desktop.open(dirToOpen);
} catch (IllegalArgumentException iae) {
System.out.println("File Not Found");
}
}
}
Note:
Desktop desktop = Desktop.getDesktop();
is not supported in JDK 5

Gokul Nath KP
- 15,485
- 24
- 88
- 126