Java 打开文件夹

 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         }

 

posted @ 2015-08-03 22:49  freshier  阅读(7021)  评论(0编辑  收藏  举报