package com.persagy.framework.util;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

import com.csvreader.CsvReader;

public class CsvUtil {
	public static List<String[]> readToStrList(String filePath, boolean skipHeader) {
		List<String[]> csvList = new ArrayList<String[]>();
		
		try {
			CsvReader reader = new CsvReader(filePath,',',Charset.forName("UTF-8"));
			
			if(skipHeader) {
				reader.readHeaders();
			}
			
			while(reader.readRecord()){
				//按行读取，并把每一行的数据添加到list集合
                csvList.add(reader.getValues());
            }
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return csvList;
	}
	
	public static void main(String[] args) {
		List<String[]> csvList = readToStrList("D:/varTest/cma_20170101.csv", true);
		System.out.println(csvList.size());
	}
}
