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)
840 questions
11
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
  • 3,317
  • 2
  • 18
  • 34
10
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
  • 796
  • 2
  • 6
  • 25
10
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,264
  • 1
  • 14
  • 27
10
votes
3 answers

Trim leading and trailing spaces in OpenCSV

I am using OpenCSV's CSVReader to read some comma separated values from a file. I'm not sure how to trim leading and trailing spaces. Sure, I could do String.trim() but it would be cleaner not to. In the documentation there is no such option…
user1377000
  • 1,313
  • 2
  • 14
  • 27
10
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
  • 45,835
  • 124
  • 360
  • 647
9
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,088
  • 12
  • 63
  • 98
9
votes
2 answers

Read remote .csv file using opencsv

I've been pondering this for a fair amount of time now. I'm trying to download the data from Yahoo!'s Stock API. When you use the API, it gives you a .csv file. I've been looking at opencsv, which seems perfect, except I want to avoid downloading…
Piccolo
  • 1,473
  • 2
  • 21
  • 35
8
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
  • 83
  • 1
  • 1
  • 7
8
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
  • 155
  • 2
  • 8
7
votes
3 answers

OpenCSV date parse

We're using OpenCSV to parse a CSV file and bind its values directly to a model object (OpenJPA entity bean) by using CsvToBean class. However, the problem is - there are some values in CSV that are (obviously) parsed as Strings, but should be set…
quantum
  • 2,681
  • 5
  • 37
  • 52
7
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,437
  • 2
  • 23
  • 40
7
votes
4 answers

how to remove double quotes while reading CSV

public class CSVTeast { public static void main(String[] args) { CSVTeast obj = new CSVTeast(); obj.run(); } public void run() { String csvFile = "D:\\text.csv"; BufferedReader br = null; …
Anandv
  • 115
  • 1
  • 3
  • 9
7
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?
ThreaT
  • 3,644
  • 13
  • 58
  • 97
7
votes
1 answer

Parse CSV to multiple/nested bean types with OpenCSV?

I have various CSVs that contain some standard columns and some completely random fields: firstname, lastname, dog_name, fav_hat, fav_color bill,smith,fido,porkpie,blue james,smith,rover,bowler,purple firstname, lastname, car_type,…
xref
  • 1,527
  • 3
  • 18
  • 37
6
votes
1 answer

opencsv not reading CSV after Android update

My code was working perfectly until my phone updated last night. I'm reading a CSV file from the phones storage into an array in my app using opencsv. This is the code... public static String[] getFileContents(File file) { String[]…
Alan Haden
  • 127
  • 14
1
2
3
55 56