0

Not a duplicate question.

I am using open csv to write csv file.

FileWriter fw= new FileWriter("file.csv");  
CSVWriter cw= new CSVWriter(fw);
cw.writeAll(trade);

but the csv file it is creating contains double quotes on all values.

I found a solution to this in this link

CSVWriter cw= new CSVWriter(fw, CSVWriter.NO_QUOTE_CHARACTER);

but the method is depreciated can anyone suggest any alternate solution?

user812142
  • 163
  • 2
  • 17
  • How are excess double quotes causing a problem? I ask because if whatever consumes this CSV doesn't understand double quotes, perhaps `CSVWriter` is generating the wrong flavour of CSV and you need to find a tool or configuration that produces the expected flavour. – Mike Samuel Mar 04 '19 at 15:14
  • Why you're ignoring the constructor mentioned as "Please use ... instead" in the JavaDoc? Doesn't it match your need? Also your solution passes `CSVWriter.NO_QUOTE_CHARACTER` incorrectly. – Tom Mar 04 '19 at 15:15

2 Answers2

1

According to the JavaDoc and the Code you just need to use the currently supported (Not deprecated) constructor:

CSVWriter cw = new CSVWriter(fw, CSVWriter.DEFAULT_SEPARATOR , CSVWriter.NO_QUOTE_CHARACTER, CSVWriter.DEFAULT_ESCAPE_CHARACTER, CSVWriter.DEFAULT_LINE_END);
Ardesco
  • 7,281
  • 26
  • 49
  • CSVWriter extends AbstractCSVWriter which implements ICSVWriter: https://sourceforge.net/p/opencsv/source/ci/master/tree/src/main/java/com/opencsv/ICSVWriter.java – Ardesco Mar 04 '19 at 15:48
  • 1
    You are right, I've just added the additional parameters to the OP's "working" answer. Tweaked the solution now to account for the typo in the original question. – Ardesco Mar 04 '19 at 15:59
0

I have got the answer in the javadoc

use this:

FileWriter fw= new FileWriter("file.csv");  
CSVWriter cw= new CSVWriter(fw);
cw.writeAll(trade,false); //here false means don't add quotes
user812142
  • 163
  • 2
  • 17