[英]How to change separator in openCSV?
I have the following code that works perfectly except for the thing that separator is still a coma:除了分隔符仍然是昏迷之外,我有以下代码可以完美运行:
CsvToBeanBuilder<CsvProductDto>(new BufferedReader(new InputStreamReader(content)))
.withSeparator('|')
.withType(CsvProductDto.class)
.withIgnoreLeadingWhiteSpace(true)
.build()
.parse()
How to change the separator?如何更改分隔符?
Ok, I've figured this out.好的,我已经想通了。 You need to build your own parser and builder, so it looks like this in Kotlin:
您需要构建自己的解析器和构建器,因此在 Kotlin 中看起来像这样:
val reader = BufferedReader(InputStreamReader(content))
val icsvParser = CSVParserBuilder().withSeparator('|').build()
val readerRfc = CSVReaderBuilder(reader).withCSVParser(icsvParser).build()
list = CsvToBeanBuilder<CsvProductDto>(readerRfc)
.withType(CsvProductDto::class.java)
.withIgnoreLeadingWhiteSpace(true)
.build()
.parse()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.