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
13
votes
5 answers

How to read from particular header in opencsv?

I have a csv file. I want to extract particular column from it.For example: Say, I have…
Yashasvi Raj Pant
  • 1,274
  • 4
  • 13
  • 33
13
votes
10 answers

Prevent opencsv from writing quotes to .csv file

I'm populating a file from a resultSet like so : while(rs.next()){ String[] entries = new String[3]; entries[0] = rs.getString(1); entries[1] = ","; entries[2] = rs.getString(2); …
blue-sky
  • 51,962
  • 152
  • 427
  • 752
13
votes
3 answers

How to read a string containing a '\' using opencsv?

When I'm reading a csv-file using opencsv it doesn't work properly when encountering a '\' at the end of a string. It makes the " part of the string, instead of the '\' as I want to. I guess there must be some method to add another '\' to have it…
Christoffer Karlsson
  • 4,539
  • 3
  • 23
  • 36
12
votes
2 answers

Athena unable to parse date using OpenCSVSerde

I have a very simple csv file on S3 "i","d","f","s" "1","2018-01-01","1.001","something great!" "2","2018-01-02","2.002","something terrible!" "3","2018-01-03","3.003","I'm an oil man" I'm trying to create a table across this using the following…
Kirk Broadhurst
  • 27,836
  • 16
  • 104
  • 169
12
votes
1 answer

Reading semicolon delimited csv

I have the below block of code which uses OpenCSV to read a CSV file and store the 7th column. The problem I face is that I use ; as delimiter in the CSV file but it takes , as delimiter as well. How can I avoid this? Putting "" in CSV is not…
Sourav Mehra
  • 435
  • 2
  • 7
  • 23
12
votes
4 answers

Java CSVReader ignore commas in double quotes

I have a CSV file that I am having trouble parsing. I am using the opencsv library. Here is what my data looks like and what I am trying to achieve. RPT_PE,CLASS,RPT_MKT,PROV_CTRCT,CENTER_NM,GK_TY,MBR_NM,MBR_PID …
KalebD
  • 121
  • 1
  • 1
  • 6
12
votes
4 answers

How to differentiate between empty string and null with OpenCSV

This is my code: CSVReader reader = new CSVReader(isReader); while ((col = reader.readNext()) != null) { String c1 = col[1]; } this is my csv file: "a","","c" "1",,"3" Is there a way I can differentiate between null and ""? OpenCSV seems to…
Gavriel
  • 18,880
  • 12
  • 68
  • 105
12
votes
2 answers

Parse from a CSV String instead of a File

I know that when you want to parse a CSV file you use: CSVReader reader = new CSVReader(new FileReader(csvPath)); But what about when you have a String csv; and you want to parse from that instead?
user1191027
11
votes
4 answers

OpenCSV Avoid using FileWriter and return InputStream

I am using OpenCsv and the new CSVWriter() method takes a Writer as an argument. What I am trying to achieve is that to avoid writing to the file system and instead return an InputStream. I am not sure how to go about this. Not very familiar with…
Aniks
  • 1,011
  • 3
  • 17
  • 29
11
votes
5 answers

Reading CSV file in resources folder android

I am developing an android app in netbeans. I am trying to read CSV file using opencsv. When I put the file in resources folder and try to read it from there, there's an error while building saying invalid resource directory. Where should I store…
Sarit Adhikari
  • 1,344
  • 2
  • 16
  • 28
10
votes
2 answers

OpenCSV wrong date format

I am using CsvToBean class of the openCSV. The bean has the date feild. @CsvDate(value = "yyyy-MM-dd") @CsvBindByPosition(position = 8) private Date startDate; I am doing the negative testing by passing the value "2018-25-02" but it is getting…
Chandresh Mishra
  • 1,081
  • 3
  • 24
  • 45
9
votes
1 answer

Why does all columns get created as string when I use OpenCSVSerde in Hive?

I am trying to create a table using the OpenCSVSerde and some integer and date columns. But the columns get converted to String. Is this an expected outcome? As a workaround, I do an explicit type-cast after this step (which makes the complete run…
ForeverLearner
  • 1,901
  • 2
  • 28
  • 51
9
votes
1 answer

java.lang.NoClassDefFoundError: org/apache/commons/lang3/ObjectUtils

I'm trying to code a program to read a CSV file and then make some stuff with it. I've searching a lot, and finally I found out this library. Some days ago I finished the code, and everything worked fine. Today I updated the library to the 4.0 v,…
Indieaiden
  • 93
  • 1
  • 1
  • 7
9
votes
3 answers

Write CSV to String using opencsv without creating an actual file or a temp file

I'm trying to use the opencsv library to write a csv file. The restriction being that I do not want to create a file on the disk or even a temp file. Is there a way I can achieve it? From what I looked, the constructor for CSVWriter requires a…
LizardKing
  • 165
  • 1
  • 2
  • 8
9
votes
3 answers

Read large CSV in java

I want to read huge data from CSV, containing around 500,000 rows. I am using OpenCSV library for it. My code for it is like this CsvToBean csvConvertor = new CsvToBean(); List list = null; try { list…
Ninad Pingale
  • 6,801
  • 5
  • 32
  • 55
1
2
3
67 68