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:
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.