Retrieve row number with supercsv

随声附和 提交于 2021-01-28 11:59:20

问题


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...

}

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


回答1:


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...

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.



来源:https://stackoverflow.com/questions/24880873/retrieve-row-number-with-supercsv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!