Search code examples
javaopencsv

How change the default separator of opencsv?


First of all, hello and sorry for the beginner question but I already saw the documentation and tutorials but I can't make it work on my code. Maybe I'm making a little mistake but I can't catch it.

I'm using the latest version of opencsv in a maven project. So I need to make a .csv file and for that I use:

try (CSVWriter writer = new CSVWriter(new FileWriter("file.csv", true)) {
    /* code
}

And everything works fine, but I need to use a diferent separator, so I try with:

try (CSVWriter writer = new CSVWriter(new FileWriter("file.csv", true), '-') {
    /* code
}

But appears Cannot resolve constructor 'CSVWriter(java.io.FileWriter, char)' in IntelliJ, when in the documentation says opencsv documentation

Any idea on how fix it? (Sorry for my english, I'm not native speaker).


Solution

  • According to the documentation, the constructor is either just the file or 5 parameters, so you cannot have just 2: http://opencsv.sourceforge.net/apidocs/com/opencsv/CSVWriter.html