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
51
votes
20 answers

OpenCSV: How to create CSV file from POJO with custom column headers and custom column positions?

I have created a MappingsBean class where all the columns of the CSV file are specified. Next I parse XML files and create a list of mappingbeans. Then I write that data into CSV file as report. I am using following annotations: public class…
Vikram Pathania
  • 623
  • 1
  • 6
  • 15
39
votes
3 answers

setting a UTF-8 in java and csv file

I am using this code for add Persian words to a csv file via OpenCSV: String[] entries="\u0645 \u062E\u062F\u0627".split("#"); try{ CSVWriter writer=new CSVWriter(new OutputStreamWriter(new FileOutputStream("C:\\test.csv"), "UTF-8")); …
mehdi
  • 686
  • 2
  • 9
  • 19
32
votes
7 answers

Unwanted double quotes in generated csv file

I have created a CSV file using the Java code below: String csv = rs.getString("UPLOAD_FOLDER_PATH")+".csv"; CSVWriter writer = new CSVWriter(new FileWriter(csv)); String [] filevalues = new…
Edward
  • 1,187
  • 7
  • 24
  • 41
29
votes
10 answers

OpenCSV - How to map selected columns to Java Bean regardless of order?

I have a CSV file with the following columns: id, fname, telephone, lname, address. I have a Person class with id, fname and lname data members. I want to map only these columns to Person object from a CSV file and discard telephone and address…
jsf
  • 2,511
  • 8
  • 28
  • 33
21
votes
5 answers

Skip first line using Open CSV reader

Here is the line i am using currently File booleanTopicFile; // booleanTopicFile is csv file uploaded from form CSVReader csvReader = new CSVReader(new InputStreamReader(new FileInputStream(booleanTopicFile), "UTF-8")); Want to skip the first line…
Sangram Anand
  • 9,494
  • 21
  • 64
  • 102
16
votes
1 answer

Parse CSV file containing a Unicode character using OpenCSV

I'm trying to parse a .csv file with OpenCSV in NetBeans 6.0.1. My file contains some Unicode character. When I write it in output the character appears in other form, like (HJ1'-E/;). When when I open this file in Notepad, it looks ok. The code…
meysam_pro
  • 215
  • 1
  • 2
  • 13
15
votes
4 answers

Writing at the end of a file via opencsv

I'm using opencsv and want to write to a .csv file through multiple sessions. However every time I start a new CSVWriter the old file gets erased. Can I change the behavior of the CSVWriter to write at the end of the file instead of replacing the…
Christian
  • 21,975
  • 33
  • 117
  • 195
15
votes
4 answers

Good and effective CSV/TSV Reader for Java

I am trying to read big CSV and TSV (tab-separated) Files with about 1000000 rows or more. Now I tried to read a TSV containing ~2500000 lines with opencsv, but it throws me an java.lang.NullPointerException. It works with smaller TSV Files with…
Robin
  • 2,996
  • 9
  • 33
  • 65
14
votes
4 answers

opencsv in java ignores backslash in a field value

I am reading a csv file using opencsv. I am ignoring the first line of; the csv file is tab separated with some values enclosed in double quotes. The problem occurs when I read the values of a column that has the '\' character, this is stripped out…
ahaneo
  • 167
  • 1
  • 4
14
votes
1 answer

How to export data to csv file in Android?

I created a csv file with the following format which I'm aiming to output to the device's sd card: Ship Name,Scientist Name,Scientist Email,Sample Volume,Sample Colour,Longitude,Latitude,Material,Date Each of the vales in the csv will be of type…
Brian J
  • 5,416
  • 19
  • 94
  • 189
12
votes
5 answers

StatefulBeanToCsv with Column headers

I am using opencsv-4.0 to write a csv file and I need to add column headers in output file. Here is my code. public static void buildProductCsv(final List product, final String filePath) { try { Writer writer = new…
Bishan
  • 14,035
  • 48
  • 151
  • 235
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
  • 6
12
votes
2 answers

opencsv CSVWriter using utf-8 doesn't seem to work for multiple languages

I have a very annoying encoding problem using opencsv. When I export a csv file, I set character type as 'UTF-8'. CSVWriter writer = new CSVWriter(new OutputStreamWriter("D:/test.csv", "UTF-8")); but when I open the csv file with Microsoft Office…
user1213162
  • 155
  • 1
  • 1
  • 5
11
votes
3 answers

Why opencsv capitalizing csv headers while writing to file

While writing Beans to CSV file by using OpenCSV 4.6, all the headers are changing to uppercase. Eventhough bean has @CsvBindByName annotation it is changing to uppercase. Java Bean: public class ProjectInfo implements Serializable { …
prasadg
  • 539
  • 6
  • 10