Hello,
I'm using CsvToBean<t> to read a text file. I need a way to obtain the line number of the text file where a bean is read.
I can't figure how to do it.
Do you have any suggest?</t>
There isn't a way to do this directly. We return a list of beans of your own creation without any metainformation.
If I had to do this myself, I would probably add a field to the bean (private int lineNumber) and make sure the input included a line number. That is probably best accomplished by overriding CSVReader.readNext() to add one more field at the beginning or end that includes the line number, which can be had from CSVReader.getLinesRead() or CSVReader.getRecordsRead(), depending on what you really need.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There isn't a way to do this directly. We return a list of beans of your own creation without any metainformation.
If I had to do this myself, I would probably add a field to the bean (private int lineNumber) and make sure the input included a line number. That is probably best accomplished by overriding CSVReader.readNext() to add one more field at the beginning or end that includes the line number, which can be had from CSVReader.getLinesRead() or CSVReader.getRecordsRead(), depending on what you really need.
Closed for lack of a response. Question presumably answered.