java读取csv文件
java读取csv文件
/** * 读取CSV文件内容 * @param csvFileName * @throws IOException */ public static void readCSVAndWrite( String inputCsvFileName1 ) throws IOException{ try { // 创建CSV读对象 CsvReader csvReader1 = new CsvReader(inputCsvFileName1); // 读表头 csvReader1.readHeaders(); String[] headers2 = {"id","XW1","XW2","XW3","XW4","XW5","XW6","XW7","XW8","GXW"}; int n=1; while (csvReader1.readRecord()){ for(int k=1;k<headers2.length;k++) { String indexHeader = headers2[k]; String cell1_value_str = csvReader1.get(indexHeader); } n++; } csvReader1.close(); } catch (IOException e) { e.printStackTrace(); }finally { System.out.println("finish..."); } }
###############################
QQ 3087438119