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
2
votes
0 answers

CsvToBean parse csv file java

public static List getCsvData(String file, Class clazz) throws IOException { try (FileReader fr = new FileReader(file)) { HeaderColumnNameMappingStrategy strategy = new HeaderColumnNameMappingStrategy<>(); …
Rocket
  • 21
  • 2
2
votes
1 answer

@CsvBindByName - Binding column with alternate column name

I have two csv sources to read data from. Both of the csv files provide the same data but with different name or column location. Is there a way to add @CsvBindByByName with "OR". For example, the headers of two files are as follows CSV 1 - RollNo,…
Karan
  • 752
  • 2
  • 13
  • 34
2
votes
0 answers

Parsing OffsetDateTime from csv using opencsv: 2021-05-09T12:23:55+0100

I'm trying to parse a csv entry "2021-05-09T12:23:55+0100" as an OffsetDateTime using openCsv as follows: @CsvDate(value = "yyyy-MM-dd'T'HH:mm:ssZ") override var orderTimeStamp: OffsetDateTime? = null Based on various suggestions from other posts,…
sigma1510
  • 1,165
  • 1
  • 11
  • 26
2
votes
2 answers

How to write list of objects in a csv using opencsv CSVWriter in java

I am trying to write some data to csv. Here is what I am trying to do: class Sample { private String id; private String type; private String name; private int value; // getter-setter } Implementation import…
Atihska
  • 4,803
  • 10
  • 56
  • 98
2
votes
0 answers

How to save CSV File React / Spring Boot in Downloads

When I directly access the api in the browser address tab, it automatically downloads the file, but when using the axios get request in the application, it does not save. I have already set-up the backend (Spring Boot) for the CSV download I can see…
Dan
  • 559
  • 4
  • 9
  • 23
2
votes
0 answers

Opencsv write list of string with ColumnPositionMapping

I have code below public class Carrier extends BaseDBClass{ @CsvBindByName private String name; @CsvRecurse private CarrierType carrierType; @CsvRecurse private LocationAddress address; @CsvBindAndSplitByName(elementType = String.class,…
ALEX
  • 124
  • 1
  • 11
2
votes
1 answer

Skip every Nth row in CSV parser

I am using opencsv parser. In my csv file there can be about 100,000 rows. It takes too much time to read them. How can I skip and read every Nth row (each 30th row for example)? private suspend fun readCSVRides(folder: String):…
Dim
  • 4,527
  • 15
  • 80
  • 139
2
votes
0 answers

Unterminated quoted field at end of CSV line

I'm trying to parse a CSV file with CSVReader. There are around 50K records in the file. Few records have comma inside the quoted string. When the parser encounters such lines, am getting the below exception java.io.IOException: Unterminated quoted…
Abirami
  • 223
  • 6
  • 21
2
votes
1 answer

opencsv throws exception when called from main, and module-info.java is present

I want to use opencsv in a project that is build with Java 14, using Java module system. So it has a module-info.java file. A call to a method in opencsv works fine when it's initiated from a unit test, but throws an exception when initiated from…
2
votes
1 answer

HIVE - escape double quote issue

I am trying to load a csv with pipe delimiter to an hive external table. The pipe occurring within data fields are enclosed within quotes. Double quotes occurring within data are escaped with \ . When I configure external table, I see data with…
Naresh S
  • 765
  • 2
  • 10
  • 19
2
votes
1 answer

OpenCSV throws Error capturing CSV header on parse

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…
Parthasarathy K
  • 121
  • 1
  • 10
2
votes
1 answer

Converting string into pojo class using opencv throwing exception

I need to convert my http response into Model and my response is plain csv format: try { StringReader stringReader = new StringReader(string); CSVReader csvReader = new CSVReaderBuilder(stringReader).build(); CsvToBean
Fay007
  • 2,707
  • 3
  • 28
  • 58
2
votes
0 answers

Mapping CSV to multiple nested beans of same type

I am trying to map CSV data row to FlightBooking bean, which has 2 nested beans of same type FlightSegment. CSV header is below for reference: Booking Date,Booking Reference,Total Price,Aviation Taxes,Flight Reference,Flight Date,Flight Price,Seat…
VivekRatanSinha
  • 596
  • 1
  • 4
  • 17
2
votes
0 answers

OpenCSV - CSVReader issue with keepCarriageReturn

I try to read in a comma separated CSV-file which looks like this: "Row ID","StringCol","idxCol" "INDEX","object","float64" "Row3","carriage return carriage return",0.0 "Row4","new line new line",1.0 "Row5","carriage return and new line …
Antje Janosch
  • 1,154
  • 5
  • 19
  • 37
2
votes
1 answer

OpenCSV all of the data storing in single line version (5.1) and data loss

Hi while saving object by using openCsv the data getting stored in a single line and if i try to add more than one object the data getting deleted of the previous object. please if anyone knows the solution answer it here. public final Logger…
Pluto_rider
  • 127
  • 1
  • 8