Share this page 

Open the default file explorerTag(s): IO


JDK1.6
Open the default file explorer.
import java.io.File;
import java.io.IOException;
import java.awt.Desktop;

public class Test {
  public static void main(String s[]) {
    Desktop desktop = null;
    // on Windows, retrieve the path of the "Program Files" folder
    File file = new File(System.getenv("programfiles"));

    try {
      if (Desktop.isDesktopSupported()) {
         desktop = Desktop.getDesktop();
         desktop.open(file);
      }
      else {
         System.out.println("desktop is not supported");
      }
    catch (IOException e){  }
  }
}