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
1 answer

mapping particular column of a csv file with particular POJO's field

I have to map particular CSV column based on index with particular POJO attributes. Mapping will be based on a json file which will contain columnIndex and attribute name which means that for a particular columnIndex from csv file you have to map…
nitin tyagi
  • 1,176
  • 1
  • 19
  • 52
3
votes
1 answer

Using OpenCSV, how can we map a record to a class that uses a Builder and not setters?

OpenCSV happily converts a record into an object if that class has a default constructor and setters for each of the fields. However, the class for which I wish to generate an object is defined with final fields, a private constructor and a Builder.…
Richard Polton
  • 101
  • 1
  • 5
3
votes
2 answers

Deprecated CSVWriter constructor

I am using OpenCSV to create CSV files filled with records from database. I am using this: CSVWriter writer = new CSVWriter( new OutputStreamWriter(new FileOutputStream("example.csv"), StandardCharsets.UTF_8),…
anon
  • 357
  • 5
  • 20
3
votes
2 answers

CsvToBeanBuilder can't convert CSV data to object

I have a simple CSV File for testing: This is my class in which I try converting the data: package Classes; import com.opencsv.bean.CsvBindByName; public class Person { @CsvBindByName private String name; @CsvBindByName private String…
plshm
  • 288
  • 3
  • 20
3
votes
1 answer

OpenCSV parse() returns object with null values

I have this input .csv file(here just a sample - there are 1.500.000 line) OBJECT_ID¦TYPE¦NAME¦PARENT_ID¦MANUFACTURER¦POSITION_CODE¦MAINTENANCE_STATUS¦PHYSICAL_STATUS 9143101068113202824¦Card¦H603CSRI - 6¦9143101069013360101¦Huawei…
Andrei Maieras
  • 696
  • 5
  • 15
  • 34
3
votes
0 answers

Create a generic method to export data with OpenCSV

I'm using OpenCSV 3.8 to write Data into CSV files. I have multiple class, Train, Tickets... So I don't want to write the same code for each class. I have done this (I removed some lines that are not important): public void…
Alkalyne
  • 153
  • 6
3
votes
2 answers

Apache common CSV formatter: IOException: invalid char between encapsulated token and delimiter

I am trying to parse a CSV file using JakartaCommons-csv Sample input file Field1,Field2,Field3,Field4,Field5 "Ryan, R"u"bianes"," dummy@gmail.com","29445","626","South delhi, Rohini 122001" Formatter:…
Emperor
  • 59
  • 1
  • 4
3
votes
5 answers

Python CSV import with nested list creation

I am trying to simply import a .csv into Python. I've read numerous documents but for the life of me I can't figure out how to do the following. The CSV format is as follows NYC,22,55 BOSTON,39,22 I'm trying to generate the following : {NYC =…
Frank Drin
  • 1,613
  • 2
  • 13
  • 18
3
votes
2 answers

Can't write JavaBeans to CSV using OpenCSV

I'm trying to write some data to a CSV file using OpenCSV. However, when I try to store the data I get a CsvBeanIntrospectionException followed with a NoSuchMethodException: Unknown property 'Email' on class 'class SubscriberBean'. Here's the code…
nikolak
  • 53
  • 7
3
votes
3 answers

OpenCSV CSVWriter does not add quote character for null element

I have a requirement where i need to wrap all elements with quote character. I am using CSVWriter to writer the lines CSVWriter writer = new CSVWriter(new FileWriter(rptFileName),`CSVWriter.DEFAULT_SEPARATOR,…
Sushil Behera
  • 817
  • 6
  • 20
3
votes
2 answers

OpenCSV - CsvReaderNullFieldIndicator seems to make no difference

I am using opencsv to create a CsvToBean like this: CsvToBean csvToBean = new CsvToBeanBuilder(new InputStreamReader(inputStream)) .withFieldAsNull(CSVReaderNullFieldIndicator.NEITHER) …
slugmandrew
  • 1,776
  • 2
  • 25
  • 45
3
votes
0 answers

OpenCSV: specify no escape character

Is there a way to specify "no escape character" in OpenCSV? I've tried setting the escape character to the empty string, but because the escape character is a primitive char in the CSVParser class (see below), there's no way for the parser to…
joshuar
  • 187
  • 2
  • 10
3
votes
3 answers

How to remove empty line at the end of the file?

I have a text file that I use to store information of Items. 10325,Test1,Producto del Hogar,12,17 10425,Test2,Videojuegos,11,17 12345,Test3,Producto del Hogar,56,17.0 I'm using opencsv library to modify one column of the desired item, I'm using…
David Selem
  • 121
  • 2
  • 15
3
votes
1 answer

Ignore double quote in the fields when parsing a CSV file using CSV parser

Sample Data - Header1, full_name, header3, header4 20, "bob, XXX", "test", 30 20, "evan"s,YYY ", "test", 30 20, "Tom, ZZZ", "test", 30 CSVReader csvReader = new CSVReader(reader, ',', '"'); The second row doesn't read as…
arun
  • 45
  • 1
  • 8
3
votes
2 answers

Parsed CSV File shows dot at the beginning

I want to parse the following CSV File: 02.01.15,Januar,GEZ,Telekommunikation,"€ 211,44",01_jährlich,Ist 02.01.15,Januar,BGV: Haftpfl. + Unfall,Versicherungen,"€ 171,95",01_jährlich,Ist I use the following code for parsing: CSVReader csvReader =…
Cellist
  • 89
  • 2
  • 11