Questions tagged [opencsv]

opencsv is a simple csv (comma-separated values) parser library for Java

What is opencsv ?

opencsv is a simple csv (comma-separated values) parser library for Java. It was developed in response to a lack of csv parsers with commercial-friendly licenses.

Where can I get it?

Source and binaries are available from Sourceforge. You can check out the javadocs online.

What features does opencsv support?

opencsv supports all the basic csv-type things you're likely to want to do:

  • Arbitrary numbers of values per line
  • Ignoring commas in quoted elements
  • Handling quoted entries with embedded carriage returns (ie entries that span multiple lines)
  • Configurable separator and quote characters (or use sensible defaults)
  • Read all the entries at once, or use an Iterator style model
  • Creating csv files from String[] (ie. automatic escaping of embedded quote chars)
1008 questions
3
votes
0 answers

Java + openCSV reading a file that contains multiple header lines

Is it possible using the opencsv library to read a file that contains several headers? While the values under the first heading are one object, and the values under the second heading are a separate object. For…
saladukha
  • 53
  • 8
3
votes
0 answers

How to generate multiple files with one controller in spring boot

Hi I have created a spring boot application to generate csv files that fetch data from database and write them into a csv file. Also I have added the functionality to select the columns that we need from the database to be included in the csv. Now I…
3
votes
1 answer

How to read a CSV file, filter by a particular record and store it in different java object based on the records

I have a CSV file like below Rahul|S|74|72|71 Randy|T|20000|2 Abinav|T|30000|3 Amrit|S|82|81|80 The above csv has information about both student's and teacher's of a school. With the help of 2nd column we will be able to identify if the information…
krishna
  • 343
  • 2
  • 5
  • 19
3
votes
0 answers

OpenCSV : getting the list of header names in the order it appears in csv

I am using Springboot + OpenCSV to parse a CSV with 120 columns (sample 1). I upload the file process each rows and in case of error, return a similar CSV (say errorCSV). This errorCSV will have only errored out rows with 120 original columns and 3…
Smiles in a Jar
  • 479
  • 1
  • 6
  • 20
3
votes
2 answers

Opencsv: Allow for a more customized error message when using @PreAssignmentValidator

Given this bean: @Data public class Contact { @PreAssignmentValidator(validator = MustMatchRegexExpression.class, paramString = "^[A-Za-z]{3,8}$") @CsvBindByName(column = "Contact First Name", required = true) private String…
alotia
  • 47
  • 1
  • 7
3
votes
2 answers

What is Coder in String Value?

I am reading a CSV file, by using com.opencsv.CSVReader Like below String[] headers = csvReader.readNext(); Value for header is coming like below screen shot: What's coder here (Highlighted in yellow)? Why the value is 1 for first index and 0 for…
3
votes
1 answer

Map a CSV element to a list of strings using OpenCsv?

I have a CSV file delimited by a single space character, like so- a b c,d,e,f m n o,p,q Here, the last element is a list of strings concatenated with the comma separator. I'm currently using the OpenCsv library to parse this CSV…
goelakash
  • 2,502
  • 4
  • 40
  • 56
3
votes
1 answer

OpenCSV Header is missing required fields found []

opencsv 5.1 Caused by: com.opencsv.exceptions.CsvRequiredFieldEmptyException: Header is missing required fields [ALGVERIFICATION, DISTAL MV, LOCATION, PREDICTED STATE, PROXIMAL MV, RUN, SAMPLE TIME]. The list of headers encountered is []. at…
xenoterracide
  • 16,274
  • 24
  • 118
  • 243
3
votes
0 answers

OpenCSV convert Object with Nested bean to csv

I am trying to map a bean to a CSV file with selected columns (not all columns) but the problem that my bean has other nested beans as attributes. Class Student { @CsvBindByName private String s_id; @CsvBindByName private String…
3
votes
1 answer

Bean to csv with optional column

How to convert my bean MyClassCsv to a CSV file with the name of an optional column? The column 'title' must be contained or not in the CSV file. The bean: @Builder @AllArgsConstructor @NoArgsConstructor @Getter @Setter public class MyClassCsv…
christo
  • 31
  • 2
3
votes
0 answers

Java OpenCSV how to catch exceptions / errors with HeaderColumnNameTranslateMappingStrategy

While trying to produce errors it's easy to produce one if you give a String when it should be a double or integer which leads to this error: Exception in thread "pool-2-thread-5" Exception in thread "pool-2-thread-8" java.lang.RuntimeException:…
CptDayDreamer
  • 1,526
  • 6
  • 25
  • 61
3
votes
2 answers

Java Opencsv parse csv with (double quotes in first name) and (comma in double quoted first name) column in csv file

I have data as follows ID1,ID2,FIRST_NAME,LAST_NAME,BIRTH_DATE,HA1,HA2,HA3,STATUS,DT 99,13863926H,MAL"COLMHS,ABBOT,1997-04-09,AMKC,RR,RR ,DE, 89,12973388H,"SAGAR,TARLE",ABDAT,1997-11-02,RNDC,RR,RR …
stackUser
  • 545
  • 3
  • 9
  • 21
3
votes
3 answers

Read CSV files with known and unknown columns in java

I'm wondering if there is a way to read csv files with known and unknown columns. For example, the column in the first csv file is: id, firstname, lastname, city, country the unknown columns are city and country the second csv file is: id,…
Gal Sosin
  • 714
  • 7
  • 27
3
votes
1 answer

How to Write Complex Java Object to CSV File

So, I know how to write a simple Java object to a CSV file, but I am having trouble with a Java object that has more complex attributes. Below is an example of what I currently have: Person.java public class Person { …
Pr0pagate
  • 199
  • 2
  • 12
3
votes
2 answers

How to read csv file into dataframe using pandas

I just got a csv file that I want to load the dataset as dataframe using pandas. However, I'm kinda confused this data format. Here is the sample of data for two lines: Name=John, Gender=M, BloodType=A, Location=New York, Age=18 Name=Mary,…
Jammy
  • 87
  • 1
  • 8