如何更改opencsv的默认分隔符?

huangapple go评论59阅读模式
英文:

How change the default separator of opencsv?

问题

抱歉,我只会为您提供翻译的部分,不会回答问题。以下是您提供的内容的翻译:

首先,你好,对于初学者的问题我感到抱歉,但我已经查看了文档和教程,但无法使它在我的代码中工作。也许我犯了一个小错误,但我抓不住它。

*我正在一个Maven项目中使用最新版本的opencsv。*所以我需要创建一个.csv文件,为此我使用以下代码:

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

一切都运行正常,但我需要使用不同的分隔符,所以我尝试了以下代码:

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

但在IntelliJ中出现了**无法解析构造函数 'CSVWriter(java.io.FileWriter, char)'**的错误,而文档中却写着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).

答案1

得分: 2

根据文档,构造函数可以是文件或5个参数,因此不能只有2个:
http://opencsv.sourceforge.net/apidocs/com/opencsv/CSVWriter.html

英文:

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

huangapple
  • 本文由 发表于 2020年8月4日 06:18:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63237672.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定