Menu

#72 Obtainng input line number using CsvToBean

v1.0 (example)
closed
None
5
2019-09-25
2019-08-30
ABrosich
No

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>

Best regards

Discussion

  • Andrew Rucker Jones

    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.

     
  • Andrew Rucker Jones

    • status: open --> closed
    • assigned_to: Andrew Rucker Jones
     
  • Andrew Rucker Jones

    Closed for lack of a response. Question presumably answered.

     

Log in to post a comment.

MongoDB Logo MongoDB