读取 csv 的指定列

有个格式规范的 csv 文件

Region,Country,City,Year,Month,Day,Support Consultant

Europe,Sweden,Stockholm,2014,12,31,B. Good

Europe,Sweden,Stockholm,2014,11,21,B. Good

North Africa/Middle East,Saudi Arabia,Riyadh,2014,12,9,E. Gipt

要求用 Java 实现:以指定的多个列号为参数,从 csv 文件中取出多列,解析为二维表。比如参数是 "#1,#3,#5" 时:

Region

City

Month

Europe

Stockholm

12

Europe

Stockholm

11

North Africa/Middle East

Riyadh

12

编写SPL代码:

=T(\"d:\\result.csv\":T(\"d:\\data.csv\",${arg_cols}))

函数T解析或写入文件,可指定多个列号。${}将字符串当表达式执行。

Java集成SPL可参考:

问题来源:https://stackoverflow.com/questions/70586145/how-to-read-a-specific-column-of-a-row-from-a-csv-file-in-java