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

opencsv writes all columns in one cell

There was a question in the past, and i have the same issue, where i try to create a simple CSV file with column headers as each header is in separate cell, there was similar question back Creating headers for CSV file but i am using exactly…
user2557930
  • 319
  • 2
  • 11
2
votes
1 answer

why do i get 'ClassNotFound' exception when using OpenCSV

I'm trying to read a CSV file using opencsv, I have imported everything and referenced the library in the classpath but i keep getting the ClassNotFoundException: Here's my code: import java.io.File; import java.io.FileNotFoundException; import…
eap99
  • 41
  • 1
  • 4
2
votes
1 answer

LiteDB import a csv

I don’t know how I can import a Csv to LiteDB. I searched a lot but don’t get a solution. I’m using asp.net core 3.1 razor pages to build a one page website and I store my data in LiteDB. Now I have data to import, but I don’t know how.
serdar
  • 23
  • 3
2
votes
1 answer

Convert DateTime from CSV file to Java field

In my csv file I have column contains date like this : my_col,... 2016-06-28 21:05:56 ADT 2016-06-28 22:05:56 ADT 2016-06-28 23:05:56 ADT I have to map this CSV file to a Java object. I tried multiple solution like : final String str = "2016-06-28…
adaso
  • 61
  • 5
2
votes
1 answer

OpenCsv - set custom validation on field

I am using OpenCsv to convert a csv file into Java Bean. My file looks like this: USER_NAME, USER_ID, FREQUENCY aaa,111,DAILY bbb,222,WEEKLY, ccc,333,MONTHLY ddd,444,SOME_RANDOM_VALUE eee,555,YEARLY I need to enforce the below validation on the…
Deepboy
  • 523
  • 3
  • 16
  • 28
2
votes
0 answers

BeanToCsv not writing to csv file

I'm working on writing a method for my discord bot that writes all the member data to a csv` file. However, I'm struggling to do so using BeanToCsv. The only output to the file is the headers and nothing else. I am able to get each field from each…
Eclipse
  • 21
  • 3
2
votes
0 answers

Write multiple classes to one CSV file

I have a list of objects that are instances of a number of sub-classes of a base class. I've been trying to write these objects out together into one CSV file. Each class contains the fields of the base class and adds a couple of extra fields of…
triadiktyo
  • 479
  • 2
  • 9
2
votes
1 answer

OpenCSV CsvToBean: First column not read for UTF-8 Without BOM

Using OpenCSV to parse UTF-8 documents without BOM results in the first column not read. Giving as an input the same document content but encoded in UTF-8 with BOM works correctly. I set specifically the charset to UTF-8 fileInputStream = new…
Daniel Rodríguez
  • 548
  • 1
  • 10
  • 30
2
votes
1 answer

OpenCSV flat to hierarchy structure data parsing

I need advice on the issue which I am facing while parsing CSV data in java. I have a CSV file with data in below format name, gender, address_first_line, address_second_line, city, number me, Male, anonymous, random, Auckland, 6545 other, Female,…
Sahil
  • 613
  • 10
  • 16
2
votes
1 answer

Is a back slash followed by a double quote valid as per CSV spec?

I am trying to parse a CSV file with openCSV CSVReader, I have some records in the file like this... "npg6851",,"Wonderful reminder\","This is perfect, I always wanted", ,"5","Nancy88","published" As this answer indicated, that sequence \" is…
AbuMariam
  • 3,282
  • 13
  • 49
  • 82
2
votes
1 answer

Groovy OpenCSV read value with backslash (e.g. "domain\user" )

In Groovy I am using opencsv to parse the CSV file. my code is not handling value with backslash. my input file has this value value1,domain\user,value2 Here is my groovy code. def filename = 'C:\\Temp\\list.txt' CSVReader csvReader = new…
sfgroups
  • 18,151
  • 28
  • 132
  • 204
2
votes
1 answer

How to solve the runtime exception while converting csv to bean using opencsv for blank csv file

Requirement: I have two csv file input.csv and output.csv The goal is to read the data rows from input.csv, then do some processing on it and if the processing fails then write the failed row of csv to output.csv Initially input.csv have some data…
Bhanu Sharma
  • 111
  • 2
  • 10
2
votes
1 answer

Adding blank line to beginning of formatted CSV

I'm trying to remove quote marks from a csv before bulk inserting using an SP (and a FMT file). The problem is our FMT file is counting on a blank line before the headers to process it, so the SP fails if there is no starting blank line. I would…
Nimchip
  • 1,685
  • 7
  • 25
  • 50
2
votes
2 answers

How to read csv file without header using opencsv?

I do know the header, but the header is parsed separately. I am using a pojo with annotations and setting it as type. My code looks like this: CsvToBean bb = new CsvToBeanBuilder(reader) …
J.J
  • 633
  • 1
  • 6
  • 14
2
votes
1 answer

Java How to add new empty column to downloaded CSV

I am using Java OpenCSV code to read data from one of the tables of MYSQL and writing resultset to CSV. Now my requirement is I want to add new empty column name in the header of that downloaded csv as the 1st column. Not sure about how and where…
Vikas J
  • 795
  • 3
  • 14
  • 31