2

I am trying to read a csv file uploaded from front-end as multipart file. Csv file uploaded is never blank.

Reader reader = new BufferedReader(new InputStreamReader(request.getFile().getInputStream()));
CSVReader csvReader = new CSVReader(reader);

These are my readers. When I do a readAll with "csvReader", I am able to get the values, so I guess no issues with file or reader.

ColumnPositionMappingStrategy<MappingModel> ms 
    = new ColumnPositionMappingStrategy<MappingModel>();
CsvToBean<MappingModel> csvToBean 
                = new CsvToBeanBuilder<MappingModel>(reader)
                .withType(MappingModel.class).withSeparator(',')
                .withMappingStrategy(ms).withIgnoreLeadingWhiteSpace(true)
                .withFieldAsNull(CSVReaderNullFieldIndicator.EMPTY_SEPARATORS)
                .withSkipLines(9).build();
List<MappingModel> mappings= csvToBean.parse(); //throwing exception

But when I do a parse with this config am getting java.lang.RuntimeException: Error capturing CSV header!

Parthasarathy K
  • 121
  • 1
  • 10
  • Does this answer your question? [How to solve the runtime exception while converting csv to bean using opencsv for blank csv file](https://stackoverflow.com/questions/53691192/how-to-solve-the-runtime-exception-while-converting-csv-to-bean-using-opencsv-fo) – Anish B. Jul 23 '20 at 04:14
  • No it didn't. I have data in excel @Anish B. – Parthasarathy K Jul 23 '20 at 10:04
  • @AnishB. Issue is resolved. Thanks for your time as well. – Parthasarathy K Jul 24 '20 at 02:04
  • @ParthasarathyK at least, you must comment about the solution pls – Erick Benites Oct 20 '20 at 03:31
  • Sorry @ErickBenites should have done. I upgraded to version 5.1.1 and removed mapping strategy. Refer to this answer. You might have solved already, hope this helps others. https://stackoverflow.com/a/48227474/1238944 – Parthasarathy K Nov 25 '20 at 17:03

1 Answers1

0

Adding to solution here for easy reference to others

I upgraded to version 5.1.1 and removed mapping strategy. Refer to this answer. https://stackoverflow.com/a/48227474/1238944

Parthasarathy K
  • 121
  • 1
  • 10