package com.java.myapp; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import au.com.bytecode.opencsv.CSVReader; public class MyClass { public static void main(String[] args) { String path = "C:\\java\\thaicreate.csv"; try { CSVReader reader = new CSVReader(new FileReader(path)); String[] row = null; ArrayList<HashMap<String, String>> myArrList = new ArrayList<HashMap<String, String>>(); HashMap<String, String> map; while((row = reader.readNext()) != null) { /*** Add Rows ***/ map = new HashMap<String, String>(); map.put("CustomerID",row[0]); map.put("Name", row[1]); map.put("Email", row[2]); map.put("CountryCode", row[3]); map.put("Budget", row[4]); map.put("Used", row[5]); myArrList.add(map); } reader.close(); // Display for (int i = 0; i < myArrList.size(); i++) { System.out.println("CustomerID = " + myArrList.get(i).get("CustomerID").toString()); System.out.println("Name = " + myArrList.get(i).get("Name").toString()); System.out.println("Email = " + myArrList.get(i).get("Email").toString()); System.out.println("CountryCode = " + myArrList.get(i).get("CountryCode").toString()); System.out.println("Budget = " + myArrList.get(i).get("Budget").toString()); System.out.println("Used = " + myArrList.get(i).get("Used").toString()); System.out.println("========================="); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท