Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a folder in explorer using Java [closed]

Tags:

java

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.

like image 961
Gett Oppus Avatar asked Apr 08 '13 09:04

Gett Oppus


2 Answers

Quite simply:

Desktop.getDesktop().open(new File("C:\\folder")); 

Note: java.awt.Desktop was introduced in JDK 6.

like image 170
Buhake Sindi Avatar answered Sep 21 '22 05:09

Buhake Sindi


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

like image 38
Gokul Nath KP Avatar answered Sep 18 '22 05:09

Gokul Nath KP