maven添加以下引用
net.sourceforge.javacsv
javacsv
2.0
test
测试代码:
public static void main(String[] args) throws IOException {
File inFile = new File("D://Desktop\\xxx\\xxx.csv"); // 读取的CSV文件
try {
BufferedReader reader = new BufferedReader(new FileReader(inFile));
CsvReader creader = new CsvReader(reader, ',');
while (creader.readRecord()) {
System.out.println(creader.getRawRecord() + "\n");
}
creader.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}
控制台打印结果,读取到的数据会用逗号分开,你也可以让它用其他字符分割。