使用标头读取CSV,同时忽略JAVA中的某些行
我正在尝试使用头读取CSV文件。我正在使用以下代码:
public String getSpecificCSVDataUsingHeader(String filePath, String header) {
String value = "";
String basePath = new File(filePath).getAbsolutePath();
try (
BufferedReader br = new BufferedReader(new FileReader(basePath));
org.apache.commons.csv.CSVParser parser = CSVFormat.DEFAULT.withDelimiter(',').withHeader().parse(br);
) {
for (CSVRecord record : parser) {
value = record.get(header);
}
return value;
} catch (IOException e) {
LogUtil.error(this, e.getMessage());
}
return value;
}
有没有什么方法可以让我在跳过其他行的同时使用标题读取csv。先谢谢你
# 1 楼答案
没有跳过不属于CSV的行的内置功能
这必须是一个自定义实现,如下所示: