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
4
votes
1 answer

Generate CSV via Apache CSV in UTF-8

how to write CSV File in UTF-8 via Apache CSV? I am trying generate csv by following code where Files.newBufferedWriter() encode text into UTF-8 by default, but when I open generated text in excel there are senseless characters. I create CSVPrinter…
Denis Stephanov
  • 4,563
  • 24
  • 78
  • 174
4
votes
1 answer

Does Apache Commons CSV framework offer a memory-efficient incremental/sequential mode for reading large files?

The Apache Commons CSV project works quite well for parsing comma-separates values, tab-delimited data, and similar data formats. My impression is that this tool reads a file entirely with the resulting line objects kept in memory. But I am not…
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
4
votes
3 answers

apache-commons-csv println method doesn't print newline in output

I'm new to apache-commons-csv 1.6 I have a basic requirement to print csv file with every record in new line. Am trying to use CSVPrinter's println method. For some weird reason, the output file doesn't have any newline character. Everything is…
thatsarunb4u
  • 53
  • 1
  • 6
3
votes
1 answer

How to verify if first line of CSV file matches the header names?

I would like to process CSV file of such structure: header1,header2 val1.1, val1.2 val2.1, val2.2 But only if the first line contains both header names - otherwise throw an exception. My current implementations using Apache Common CSV is: Reader…
mar3g
  • 101
  • 1
  • 7
3
votes
2 answers

Apache commons CSV ignore corrupted or invalid records in a csv file and continue parsing

I am trying to parse an almost valid CSV file containing data that is 99.9% correct and valid. However halfway through there are a couple of records that are invalid (too many quotes) e.g. a,b,"c",d a,b,""c""",d My code try (Reader reader =…
Steve Fitzsimons
  • 3,754
  • 7
  • 27
  • 66
3
votes
2 answers

Apache Commons CSV doesn't ignore missing column

Using Apache Commons CSV for parsing, but doesn't ignore missing column and throws exception. with this sample data: name age Ali 35 John 25 Vahid 75 Below code record.get(DataColumns.surname) throws java.lang.IllegalArgumentException: Mapping for…
nikli
  • 2,281
  • 2
  • 24
  • 38
3
votes
4 answers

csvParser.getRecords() returns empty when there are records in CSVParser

I'm using following dependency for reading the csv file: org.apache.commons commons-csv 1.5 Below is the code that I've written to read the csv…
User1230321
  • 1,435
  • 4
  • 23
  • 39
3
votes
1 answer

Apache Commons CSV: Avoiding IllegalArgumentException if header does not exist

I have a CSV file that contains 3 headers A, B, C. In my code I use CSVReader's get method to access the values in these headers. Is there a way I can CSVFormat to avoid a get() IllegalArgumentException if I use the same code to process a file with…
3
votes
1 answer

How do I instruct CSVPrinter to not write a header line when adding a record?

I have a CSV file that's created by a program other than the one I'm writing, so I can't change the headers. The headers for the file are ControllerID,Event,Number,ReaderID,Timestamp,TransactionID,. I have specified the same headers to the…
Agi Hammerthief
  • 2,114
  • 1
  • 22
  • 38
3
votes
2 answers

Apache common CSV formatter: IOException: invalid char between encapsulated token and delimiter

I am trying to parse a CSV file using JakartaCommons-csv Sample input file Field1,Field2,Field3,Field4,Field5 "Ryan, R"u"bianes"," dummy@gmail.com","29445","626","South delhi, Rohini 122001" Formatter:…
Emperor
  • 59
  • 1
  • 4
3
votes
1 answer

How to read csv file of excel using apache csv

I have a CSV file(excel) in which each data is available in cell like excel. I'm using Apache CSV to parse excel type csv. While parsing the data my each character is getting separated by null character in between. This CSV file I'm getting from…
Pat's
  • 43
  • 6
3
votes
3 answers

csv-commons - withSkipHeaderRecord option doesn't skip anything

I have usual csv file with header f1, f2, f3 1, 2, 3 and I try to parse it: Iterable records = CSVFormat.EXCEL.withIgnoreEmptyLines().withSkipHeaderRecord().parse(in); records.forEach(record -> { ... But…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
3
votes
0 answers

Csv-commons withIgnoreEmptyLines method doesn't have affect

I wrote following code: Iterable records = CSVFormat.EXCEL.withIgnoreEmptyLines().withSkipHeaderRecord().parse(in); records.forEach(record -> {... foreach lambda invokes for empty lines too. I have empty lines because of excel. empty…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
3
votes
2 answers

Apache CSV - Convert List to CSVRecord

I'm inclined to use CSVRecord because it can be used to map with a header and get the corresponding value. My application frequently uses CSVRecord class. However, I cannot instantiate the CSVRecord. I would prefer not to modify the source/create a…
dmachop
  • 824
  • 1
  • 21
  • 39
3
votes
1 answer

Ignore double quote in the fields when parsing a CSV file using CSV parser

Sample Data - Header1, full_name, header3, header4 20, "bob, XXX", "test", 30 20, "evan"s,YYY ", "test", 30 20, "Tom, ZZZ", "test", 30 CSVReader csvReader = new CSVReader(reader, ',', '"'); The second row doesn't read as…
arun
  • 45
  • 1
  • 8