用supercsv检索行号 [英] Retrieve row number with supercsv

查看:55
本文介绍了用supercsv检索行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

super-csv 库是否可以找到要处理的文件的行号?

Is there a way with the super-csv library to find out the row number of the file that will be processed?

换句话说,在我开始使用循环处理行之前:

In other word, before i start to process my rows with a loop:

while ((obj = csvBeanReader.read(obj.getClass(),
csvModel.getNameMapping(), processors)) != null) { 

 //Do some logic here...

}

我可以使用某些库类检索csv文件中包含的行数吗?

Can i retrieve with some library class the number of row contained into the csv file?

推荐答案

否,要查明CSV文件中有多少行,您必须使用Super CSV读取整个文件(这实际上是CSV只能跨多行).您总是可以使用 CsvListReader 对文件进行初始传递(它不执行任何bean映射,因此可能更有效)只是为了获取行数...

No, in order to find out how many rows are in your CSV file, you'll have to read the whole file with Super CSV (this is really the only way as CSV can span multiple lines). You could always do an initial pass over the file using CsvListReader (it doesn't do any bean mapping, so probably a bit more efficient) just to get the row count...

顺便说一句(在这种情况下无济于事),您可以使用 getLineNumber() getRowNumber从阅读器获取当前行/行号()方法.

As an aside (it doesn't help in this situation), you can get the current line/row number from the reader as you are reading using the getLineNumber() and getRowNumber() methods.

这篇关于用supercsv检索行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆