Including double quotes while writing CSV using apache commons in java

Harshit :

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 really want to get rid of double quotes here. Please find below code for the same.

CSVFormat format = CSVFormat.DEFAULT;
FileWriter fw = new FileWriter("Temp.csv");
CSVPrinter printer = new CSVPrinter(fw, format);

String[] temp = new String[4];

for(int i=0; i<4; i++) {
    if(i==1)
        temp[0] = "#";
    else
        temp[0] = "";
    temp[1] = "hello" + (i+1);
    temp[2] = "";
    temp[3] = "test";

    Object[] temp1 = temp[]
    printer.printRecord(temp1);
}

fw.close();
printer.close();

Temp.csv

"",hello1,,test
"#",hello2,,test
"",hello3,,test
"",hello4,,test

I don't want a quote character at the beginning of every row. I just want an empty string without quotes, same as in column 3. Can anyone help?

lars :

This is a known issue. You can vote for it in the apache commons csv issue tracker:

https://issues.apache.org/jira/browse/CSV-63

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

skip double quotes when reading csv file using apache commons csv

remove double quotes from csv while using open csv

Regex for CSV split including multiple double quotes

Writing CSV file using Spark and java - handling empty values and quotes

How to add both double quotes and triple Quotes in String header while generating CSV using CSVFormat

Generate string content for CSV with Apache Commons in Java instead of writing an actual file

Escape double quotes while writing a JSON file using Unix shell script

Writing double quote into csv is resulting in three double quotes

how to remove double quotes while reading CSV

JAVA CSV writing Space without quotes

Get CSV file header using apache commons

How to control double quotes when writing R .csv files

Spark dataframe not writing Double quotes into csv file properly

Read CSV files in Java using Apache Commons CSV for loop starting index 1

The system cannot find the file specified while starting a windows service from a Java App using Apache Commons Daemon

Download file using java apache commons?

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

Java - Write CSV File with Apache.commons.csv

Avoid double quotes around column while spooling to csv from oracle

Using quotes and double quotes in Java Runtime.getRuntime().exec(...)

Escaping double quotes in .csv

Having problems while writing a .CSV file in Java?

Dataweave Escape Double Quote and , while reading a json and writing to csv

PostgreSQL COPY csv including Quotes

Difference between angle bracket < > and double quotes " " while including header files in C++?

Unable to Parse header from github CSV URL using Apache Commons

Using Apache Commons CSV to read file starting from the second line

CSV parsing with Commons CSV - Quotes within quotes causing IOException

How to replace double quotes from csv inside a tag using Regex