PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, August 27, 2022

[FIXED] Why does CsvBindByPosition just return one column value line by line?

 August 27, 2022     csv, java, opencsv     No comments   

Issue

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'


Solution

Go for:

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

and you should see better results.



Answered By - MWiesner
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing