OpenCSV如果我有' |'作为','
我的代码是:
CSVReader reader = new CSVReaderBuilder(new FileReader("C://Users//himanshurai//eclipse-workspace//nike.csv")).withSeparator('|').withSkipLines(1).build();
List<TShirt> tShirtList = reader.readAll().stream().map(data -> {
//TShirt tShirt = new TShirt(data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
TShirt tShirt = new TShirt();
tShirt.setId(data[0]);
tShirt.setName(data[1]);
tShirt.setColor(data[2]);
tShirt.setGender(data[3]);
tShirt.setSize(data[4]);
tShirt.setPrice(data[5]);
tShirt.setRating(data[6]);
tShirt.setIsAvailable(data[7]);
return tShirt;
}).collect(Collectors.toList());
tShirtList.forEach(System.out::println);
这是我的CSV文件:
我认为这是因为CSV文件具有'|'作为一个分离器,而不是“”,我尝试使用withperator('|')方法,但它显示出错误的错误。还有其他方法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的。因此,除了原始的拼写错误外,我认为您正在获得
csvparserbuilder
和csvReaderBuilder
类混合。根据,您应该这样使用它们:
请注意,
withSeparator
方法在csvparserbuilder
notcsvReaderBuilder
。(当我仔细看...我发现在此不匹配源代码。
OK. So, in addition to the original spelling error, I think you are getting the
CSVParserBuilder
andCSVReaderBuilder
classes mixed up.According to the source code, you should be using them like this:
Notice that the
withSeparator
method is onCSVParserBuilder
notCSVReaderBuilder
.(When I looked carefully ... the javadoc that I found here doesn't match the source code. It shows
withSeparator
in the example, but not in the method list. Go figure.)