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

ResultSet to CSV format string

I am trying to convert a ResultSet object to a String object in CSV format. I've tried using OpenCV to convert it into CSV file but I need to have it as a string. There is an option to first convert it into a file and then convert the data into a…
HyperioN
  • 3,433
  • 2
  • 22
  • 36
5
votes
3 answers

Reading large CSV files in Java

I am trying to read a 1,000,000 lines CSV file in Java. I'm using OpenCSV library, and it works fine on a smaller file of 30,000 lines. Processes it in under half a second. But when I try to read from a million line file, it never finishes. Now I…
Damir Pasic
  • 51
  • 1
  • 2
5
votes
2 answers

How to write bean to CSV using OpenCSV without converting to String[]?

I have a large array of a bean that needs to be written to a CSV file. I am trying to use OpenCSV but all the examples I see on the web ask me to convert the bean (POJO) that I have to a string array. I don't want to do this since this would mean I…
jobin
  • 2,600
  • 7
  • 32
  • 59
5
votes
2 answers

Double Quotes getting duplicated while writing CSV file with OpenCSV

I am trying to write a simple CSVWriter code using OpenCSV library but having a strange issue with it. Code: public class Test { public static void main(String[] args) throws IOException { String[] header = {"ONE", "\"TWO\"",…
Asif
  • 4,980
  • 8
  • 38
  • 53
5
votes
3 answers

Java Spring - dynamically generated csv file download response is hanging

On my company's site we have some tables that we need to export to a csv file. There are some varying parameters, so the csv file needs to be dynamically created on request. My problem is that after clicking to download, the response hangs, and…
jonny bordo
  • 549
  • 3
  • 7
  • 17
5
votes
1 answer

OpenCSV can't read InputStream created by Jersey2

I have the following code: @POST @Path("/csv") @Consumes(MediaType.MULTIPART_FORM_DATA) public String populateCSV(@FormDataParam("data") InputStream fileInputStream) throws JsonParseException, JsonMappingException, IOException { …
Dejell
  • 13,947
  • 40
  • 146
  • 229
5
votes
2 answers

delete a row in csv file

I am appending the data to the last row of a csv. I wanted to delete the existing row and then rewrite it with the appended element. Is there any way of deleting the row in csv? I am using opencsv to read and the write the file. I tried using…
user3453784
  • 593
  • 3
  • 9
  • 19
5
votes
1 answer

opencsv not writing to a file

I am using opencsv 3.0 version. For some reason it is not writing out the records to the CSV file. It worked fine with version 2.3. However, I wanted to use the CSVIterator class. Any help is appreciated. public void writeGradesIntoFile(GradeReport…
user3453784
  • 593
  • 3
  • 9
  • 19
5
votes
1 answer

Opencsv + add new column to existing csv

It there any possibility to add a new column to existing csv file, means existing file userid,name 1,Jim 2,Sally 3,Bob modified output file userid,name,time 1,Jim,64913824823208 2,Sally,64913824900056 3,Bob,64913824966956 Thanks in advance
5
votes
3 answers

Spock: Reading Test Data from CSV File

I'm trying to write an elegant Spock specification that will read a very large test data from CSV file without loading all the data into the memory. I'm looking for your feedback on how you might do it better than what I currently have here. Let's…
limc
  • 39,366
  • 20
  • 100
  • 145
4
votes
2 answers

How to skip embedded "newlines" in a csv file using OpenCSV

I have a csv file which contains 5 fields with 1 field having embedded newlines. I can read the csv file perfectly using CSVReader [OpenCSV]. I am also able to get individual fields in spite of the embedded newlines. But I want to write another csv…
mihirk
  • 93
  • 1
  • 3
  • 10
4
votes
2 answers

writeAll(ResultSet res,Boolean b) method of opencsv adds double quotes around data

When I use this function to write to a csv file all the data is embedded in double quotes. Is there a way to write to csv file without the double quotes? CSVWriter writer = new CSVWriter(new FileWriter(table+".csv"), '\t'); …
Shamis Shukoor
  • 2,515
  • 5
  • 29
  • 33
4
votes
1 answer

How change the default separator of opencsv?

First of all, hello and sorry for the beginner question but I already saw the documentation and tutorials but I can't make it work on my code. Maybe I'm making a little mistake but I can't catch it. I'm using the latest version of opencsv in a maven…
user13702872
4
votes
2 answers

openCSV with complex bean structure

I try to map a nested bean structure with openCSV. I found the @CsvRecurse annotation, but this does not seem to work if a nested bean is used multiple times. What options do I have to solve this? Example (adapted from the docs linked above) Data…
Iris Hunkeler
  • 208
  • 1
  • 10
4
votes
1 answer

Create CSV or TXT file in app and save it to 'download' folder - Android

I searched and tried a lot before asking this. But all the code that I'm trying is not working. I want the file to be stored in the download folder and be accessible from the user also if he uninstalls the app. I also tried using opencsv library.…