Questions tagged [apache-commons-csv]

Commons CSV reads and writes files in variations of the comma-separated value (CSV) format.

Apache Commons CSV, an open-source Java library for reading and writing text files in various delimited-text formats, including:

114 questions
57
votes
5 answers

No header mapping was specified, the record values can't be accessed by name (Apache Commons CSV)

I got this error message happening when I'm trying to read a csv: Exception in thread "main" java.lang.IllegalStateException: No header mapping was specified, the record values can't be accessed by name at…
Creature
  • 994
  • 1
  • 12
  • 27
37
votes
5 answers

Invalid char between encapsulated token and delimiter in Apache Commons CSV library

I am getting the following error while parsing the CSV file using the Apache Commons CSV library. Exception in thread "main" java.io.IOException: (line 2) invalid char between encapsulated token and delimiter at…
Santhosh Sridhar
  • 641
  • 1
  • 6
  • 12
16
votes
9 answers

How can I skip the first line of a csv in Java?

I want to skip the first line and use the second as header. I am using classes from apache commons csv to process a CSV file. The header of the CSV file is in the second row, not the first (which contains coordinates). My code looks like this:…
Medusa
  • 593
  • 2
  • 5
  • 18
16
votes
6 answers

Get CSV file header using apache commons

I have been looking for the past 2 hours for a solution to my problem in vain. I'am trying to read a CSV File using Apache commons ,I am able to read the whole file but my problem is how to extract only the header of the CSV in an array?
user3382344
  • 177
  • 1
  • 1
  • 8
15
votes
2 answers

How can I process a large file via CSVParser?

I have a large .csv file (about 300 MB), which is read from a remote host, and parsed into a target file, but I don't need to copy all the lines to the target file. While copying, I need to read each line from the source and if it passes some…
Alex Orlov
  • 171
  • 1
  • 1
  • 6
14
votes
3 answers

How to parse a CSV file that might have one of two delimiters?

In my case, valid CSV are ones delimited by either comma or semi-colon. I am open to other libraries, but it needs to be Java. Reading through the Apache CSVParser API, the only thing I can think is to do this which seems inefficient and…
Coder1224
  • 1,785
  • 2
  • 17
  • 21
13
votes
3 answers

Java - Write CSV File with Apache.commons.csv

I'm using the apache.commons.csv library in Java. I'm reading a CSV file from a web page with this code: InputStream input = new URL(url).openStream(); Reader reader = new InputStreamReader(input, "UTF-8"); defaultParser = new…
jonbon
  • 1,142
  • 3
  • 12
  • 37
11
votes
2 answers

Including double quotes while writing CSV using apache commons in java

I am using apache commons CSV to write csv files. I want to stick to this library. While I am writing a csv file, in the first column of generated file, it contains double quotes as quote character and other columns are generated as expected. I…
Harshit
  • 617
  • 1
  • 6
  • 15
9
votes
4 answers

Apache Commons CSV Mapping not found

I am trying to read a CSV file with certain headers into a Java object using Apache Commons CSV. However, when I run the code, I get the following exeption: Exception in thread "main" java.lang.IllegalArgumentException: Mapping for Color not found,…
Norman Percy
  • 858
  • 1
  • 8
  • 13
7
votes
5 answers

CSV parsing with Commons CSV - Quotes within quotes causing IOException

I am using Commons CSV to parse CSV content relating to TV shows. One of the shows has a show name which includes double quotes; 116,6,2,29 Sep 10,""JJ" (60 min)","http://www.tvmaze.com/episodes/4855/criminal-minds-6x02-jj" The showname is "JJ" (60…
mhollander38
  • 775
  • 3
  • 11
  • 22
7
votes
1 answer

Mocking an Apache Commons CSV CSVRecord

At some point my code needs to touch a CSVRecord and I can't figure out a way to create a mock version of it. The class is final so it can't be mocked. The constructor is private so I can't create an instance of it. How does one approach testing…
Martinffx
  • 2,426
  • 4
  • 33
  • 60
7
votes
1 answer

Why does Apache Commons CSVParser.getHeaderMap() always return null?

When reading the following TSV snippet with Apache Commons CSV: Name DOB SIN Address, contact information "Patience Middleton" "18-4-87" 720463771 "varius Cras sem aliquam taciti fames hendrerit tempor" This is my code: CSVFormat format =…
tribbloid
  • 4,026
  • 14
  • 64
  • 103
6
votes
2 answers

How to convert List to the csv byte array safely?

Initially I had the following code: Attempt 1 try (var output = new ByteArrayOutputStream(); var printer = new CSVPrinter(new OutputStreamWriter(output), CSVFormat.DEFAULT)) { printer.printRecord(EMAIL); for (MyBean mb : items) { …
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
6
votes
3 answers

Error Parsing due to CSV Differences Before/After Saving (Java w/ Apache Commons CSV)

I have a 37 column CSV file that I am parsing in Java with Apache Commons CSV 1.2. My setup code is as follows: //initialize FileReader object FileReader fileReader = new FileReader(file); //intialize CSVFormat object CSVFormat csvFileFormat =…
corneria
  • 608
  • 3
  • 11
  • 24
6
votes
3 answers

Apache Commons CSV - case insensitive headers?

Is there a built-in feature in Apache CSV implementation to ignore header case when reading csv? Some time ago we have implemented utility for converting CSV export files to SQL. For that we have choosen Apache CSV. Everything was perfectly fine…
Kousalik
  • 3,111
  • 3
  • 24
  • 46
1
2 3 4 5 6 7 8