<span style="white-space:pre"></span>//如果是瀏覽器運行,就不需要寫WebContent/ 了String path = "WebContent/config";File file = new File(path);File[] tempList = file.listFiles();System.out.println("該檔案夾目錄下對象的個數:" + tempList.length); <span style="white-space:pre"></span> /** <span style="white-space:pre"></span>* 讀取csv檔案裡的資料 <span style="white-space:pre"></span>* 因為要擷取檔案只是csv的檔案,所以截取字串,把檔案類型擷取出來,此處就是擷取字串的最後三個字元 <span style="white-space:pre"></span>*/for (int i = 0; i < tempList.length; i++) {if (tempList[i].isFile()) {System.out.println("文 件:" + tempList[i]);ArrayList<String[]> csvList = new ArrayList<String[]>(); // 用來儲存資料String csvPath;csvPath = tempList[i].getPath();String type = csvPath.substring(csvPath.length() - 3, csvPath.length());System.out.println(type);if (type.equals("csv")) {CsvReader reader = new CsvReader(csvPath, ',', Charset.forName("SJIS")); // 一般用這個編碼就可以了reader.readHeaders(); // 跳過表頭while (reader.readRecord()) { // 逐行讀入出表頭的資料csvList.add(reader.getValues());}reader.close();for (int row = 0; row < csvList.size(); row++) {String cell = csvList.get(row)[0] + "," + csvList.get(row)[1]; // 取得第row行第0列的資料System.out.println(cell);}}} else if (tempList[i].isDirectory()) {System.out.println("檔案夾:" + tempList[i]);} 此截圖就是檔案所存放的路徑