1.添加maven依赖
<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-csv</artifactId> <version>1.4</version> </dependency>
2. 相关代码
public static List<CSVRecord> getcsvRecordListFromStr(String buff) throws IOException { ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(buff.getBytes()); Reader csvReader = new InputStreamReader(tInputStringStream, "UTF-8"); CSVParser csvParser = new CSVParser(csvReader, CSVFormat.EXCEL.withHeader()); List<CSVRecord> csvRecordList = csvParser.getRecords(); return csvRecordList; }
List<CSVRecord> records = CommonUtils.getcsvRecordListFromStr(buff); records.remove(0); for(CSVRecord record:records) { String settlementDay = record.get("结算日期\t").trim();
}