我正在使用apache commons csv从 CSV 文件中读取内容,我从谷歌趋势中下载为相关查询部分右下角的 csv。文件的一小部分:
Category: All categories
"bluetooth speakers: (1/1/04 - 8/15/16, Worldwide)"
TOP
speaker,100
bluetooth speaker,100
RISING
portable speakers bluetooth,Breakout
portable speakers,Breakout
我从文件中读取的代码:
private void readCsv(String inputFilePath) {
try {
Reader in = new FileReader(inputFilePath);
Iterable<CSVRecord> records = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(in);
for (CSVRecord record : records) {
String topic = record.get(0);
if (topic != null && !topic.isEmpty()) {
System.out.println(topic);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
输出:
bluetooth speakers: (1/1/04 - 8/15/16, Worldwide)
TOP
speaker
bluetooth speaker
RISING
portable speakers bluetooth
portable speakers
期望的输出:
speaker
bluetooth speaker
portable speakers bluetooth
portable speakers
根据来自谷歌的数据(没有标题)和两个标题TOP和RISING我无法提取所需的值。是否有任何过滤配置我可以应用以获得所需的值?