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...");
    }
}

 

 

 

###############################

posted @ 2022-12-06 13:29  西北逍遥  阅读(398)  评论(0编辑  收藏  举报