我使用FasterXML 库来解析我的CSV file
. 第一CSV file
行有列名。不幸的是,我需要重命名列。我有一个 lambda 函数,我可以在其中传递红色值csv file
in 传递红色值并获取新值。
我的代码看起来像这样,但不起作用。
CsvSchema csvSchema =CsvSchema.emptySchema().withHeader();
ArrayList<HashMap<String, String>> result = new ArrayList<HashMap<String, String>>();
MappingIterator<HashMap<String,String>> it = new CsvMapper().reader(HashMap.class)
.with(csvSchema )
.readValues(new File(fileName));
while (it.hasNext())
result.add(it.next());
System.out.println("changing the schema columns.");
for (int i=0; i < csvSchema.size();i++) {
String name = csvSchema.column(i).getName();
String newName = getNewName(name);
csvSchema.builder().renameColumn(i, newName);
}
csvSchema.rebuild();
当我稍后尝试打印出这些列时,它们仍然与我的第一行相同CSV file
.
另外我注意到,这csvSchema.size()
等于0
- 为什么?