Home > Enterprise >  Why does CsvBindByPosition just return one column value line by line?
Why does CsvBindByPosition just return one column value line by line?

Time:08-12

i try to read a csv file with opencsv

Prozess;Rüstvorgang;Prozessdauer Minuten;Station;Küvettentyp;Küvettentemperatur Grad Celsius;Werker;Gasmischung;GasKonzentration PPM
Test;X;;Y;K10;;X1;;
ACVB;;60;ERT;K10;400;;;
SSD;;10;ERER;K10;400;X;;

My class:

public class ABC
{
   @CsvBindByPosition(position = 0)
   private String prozess;
   @CsvBindByPosition(position = 1)
   private String ruestVorgang;
   @CsvBindByPosition(position = 2)
   private String prozessDauerMinuten;
   @CsvBindByPosition(position = 3)
   private String station;
   @CsvBindByPosition(position = 4)
   private String kuevettenTyp;
   @CsvBindByPosition(position = 5)
   private String kuevettenTemperatur;
   @CsvBindByPosition(position = 6)
   private String werker;
   @CsvBindByPosition(position = 7)
   private String gasMischung;
   @CsvBindByPosition(position = 8)
   private String gasKonzentration;

The beanBuilder

List<ABC> beans = new CsvToBeanBuilder(new FileReader("etestcsv"))
               .withType(ABC.class)
               .build()
               .parse();

Just the prozess is filled with the values of all columns, the rest is null. I tried also with CsvBindByName but everything is null. implementation 'com.opencsv:opencsv:5.3'

CodePudding user response:

Go for:

List<ABC> beans = new CsvToBeanBuilder(new FileReader("etestcsv"))
               .withType(ABC.class)
               .withSeparator(';')
               .build()
               .parse();

and you should see better results.

  • Related