Contents ...
udn網路城邦
[Java] 取得 某個資料夾下的檔案清單
2008/06/06 16:31
瀏覽16,047
迴響0
推薦0
引用0
    /**
     * 輸入資料夾的路徑, 顯示得該資料夾下的所有檔案
     * @param String folderPath
     * @author Lupin
     **/
    public void getFileList(String folderPath){
        //String folderPath = "C:\\";//資料夾路徑
        StringBuffer fileList = new StringBuffer();
            try{
               java.io.File folder = new java.io.File(folderPath);
               String[] list = folder.list();          
                         for(int i = 0; i < list.length; i++){
                             fileList.append(list[i]).append(", ");
                        }
                }catch(Exception e){
                      System.out.println("'"+folderPath+"'此資料夾不存在");
                }
                System.out.println(fileList);
        }
}
發表迴響

會員登入