1 package com.swing.demo; 2 3 import java.io.File; 4 import java.io.IOException; 5 6 public class OpenDirTest { 7 public static void main(String[] args) { 8 try { 9 java.awt.Desktop.getDesktop().open(new File("D:\Java")); 10 } catch (IOException e) { 11 e.printStackTrace(); 12 } 13 } 14 }
备用方式:
1 try { 2 String[] cmd = new String[5]; 3 cmd[0] = "cmd"; 4 cmd[1] = "/c"; 5 cmd[2] = "start"; 6 cmd[3] = " "; 7 cmd[4] = FILE_PATH; 8 Runtime.getRuntime().exec(cmd); 9 } catch (IOException e) { 10 e.printStackTrace(); 11 }