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
3
votes
0 answers

CSVPrinter quotes the value even when it does not have a delimiter or line separator

When CSVFormat's quoteMode is set to MINIMAL, it should quote the value only when the value contains a delimiter (,) or line separator '\n' according to the javadoc. But it does quoting even if the value contains hash (#). Please see below example…
Nitiraj
  • 614
  • 1
  • 4
  • 15
3
votes
1 answer

Passing Header row index to Apache Commons CSV

Apache Commons CSV provides method to pass Header columns with withHeaders(). But is there a way to pass a specific row index as header row to Apache Commons. I have gone through the docs but have not found anything.
Rama Arjun
  • 273
  • 2
  • 3
  • 15
3
votes
1 answer

Get raw record in Apache CSV

How to get the raw record, i.e. the line the way it is in the csv file, as a string when using Apache CSV
Noor
  • 19,638
  • 38
  • 136
  • 254
2
votes
0 answers

Which apache commons CSV parser to use? SOLR CSV or commons CSV? Are they both the same?

Possible Duplicate: csv api for java There doesn't seem to any dev on commons-csv and solr-commons-csv mentions it is specifically intended for apache-solr/lucene. What is the preferred CSV parser you use? Should I just go with one of them, this…
chinto
  • 1,486
  • 17
  • 27
2
votes
2 answers

CSVFormat add quotation to header

I am using apache.commons.csv to create a CSV file. When generating the file ,I want to parse a header with the method .withHeader(). The values I parse should have quotes like "FILENAME". To do that I want to use an enum class. However I am not…
user15980267
  • 47
  • 1
  • 4
2
votes
1 answer

Is there a way to put a custom separator for CSV file using CSVParser?

Currently, I am using this tutorial on how to read CSV file: https://stackabuse.com/reading-and-writing-csvs-in-java-with-apache-commons-csv/ It used CSVParser and CSVFormat from Apache-commons-csv. It can read perfectly fine but not in a way that I…
Gagak
  • 129
  • 2
  • 13
2
votes
1 answer

How to skip headers in csv file when headers exists

I am using apache-common-csv to import data from the CSV file and I would like to skip headers in the first line. What is important, the file sometimes can contain headers but sometimes not. I have an implementation like below but the result not…
db9
  • 123
  • 1
  • 10
2
votes
3 answers

How to append new row using Apache Common CSV CSVPrinter?

I have this class containing a method to generate CSV file using Apache Common CSV library 1.5 public class CSVGenerator { private static final String CSV_FILE = "./credentials.csv"; private static CSVPrinter csvPrinter; public…
keylogger
  • 822
  • 3
  • 19
  • 39
2
votes
2 answers

Write CSV from List of HashMaps with Header using Apache Commons CSV

I have to take an ArrayList of HashMap and create a CSV using Apache Commons CSV. However, it's not writing the values to the right headers. Is there an easy way to have the library automatically place the values to the right headers using the Enum?…
trilogy
  • 1,738
  • 15
  • 31
2
votes
2 answers

Apache Commons CSV parser: Not able to read the values

I am using apache commons CSV parser to convert the CSV to a map. In the map I couldnt able to read some values through intellij debuger. if I manually type map.get("key") the value is null. However, if I copy paste the key from the map, I am…
Minisha
  • 2,117
  • 2
  • 25
  • 56
2
votes
2 answers

Why is CSVParser is reading the next CSVRecord

Using org.apache.commons.csv.CSVParser I am having a strange behavior. I am trying to read, line by line, a csv file delimited by ; but my parser is skipping line for an unknown reason. Here is my code: public static void main(String[] args) { …
Sebastien
  • 1,308
  • 2
  • 15
  • 39
2
votes
4 answers

Inserting blank line in csv using java

I want to insert a blank line in csv using java. I have written following code: CSVFormat csvFileFormat = CSVFormat.DEFAULT.withRecordSeparator("\n").withEscape('\\'); FileWriter fileWriter = new FileWriter(csvFile); CSVPrinter csvFilePrinter = new…
Radhika Kulkarni
  • 298
  • 1
  • 4
  • 19
2
votes
2 answers

How to update a record in csv file using Apache commons csv api in java?

I have a csv file written using Apache commons API and I also can read the file, however I'm unable to know how to edit a record value in the csv file using Apache commons API, need help on this.
Suresh
  • 1,491
  • 2
  • 22
  • 27
2
votes
0 answers

Apache commons csv how to edit specific column from csv file

I can read the csv file with the below code, Reader inRead = new FileReader("testfile.csv"); Iterable records = CSVFormat.EXCEL.parse(inRead); for (CSVRecord record : records) { String lastName = record.get("Name"); } But, I want to…
sam
  • 31
  • 3
2
votes
1 answer

Java reading csv file with multiple headers

I am using apache commons csvto read contents from a CSV file I get from google trends downloaded as a csv in related query section bottom right. A small subset of the file: Category: All categories "bluetooth speakers: (1/1/04 - 8/15/16,…
Illegal Argument
  • 10,090
  • 2
  • 44
  • 61