【发布时间】:2016-01-26 18:10:34
【问题描述】:
我有 3 个 csv 文件。每个文件包含 10 列,但其中只有 1 列具有不同的值。
如图所示,每种语言只有目的地名称不同。
如何将列放在现有列之间以及如何更改它们的标题(DEST_NAME_DISPLAY --> DEST_NAME_EN)?
到目前为止,除了使用 Super csv 读取 csv 文件之外,我对 csv 操作几乎没有经验
到目前为止我所知道的示例
public List<City> readWithCsvMapReader(String file, String source) throws IOException, AuthenticationException, RepositoryException {
ICsvMapReader mapReader = null;
FileInputStream stream = new FileInputStream(file);
InputStreamReader reader = new InputStreamReader(stream, ENCODING);
try {
mapReader = new CsvMapReader(reader, PREFERENCE);
final String[] header = mapReader.getHeader(true);
final CellProcessor[] processors = getProcessors();
Map<String, Object> locationMap;
while ((locationMap = mapReader.read(header, processors)) != null) {
/*do some logic*/
}
} finally {
if (mapReader != null) {
mapReader.close();
}
}
}
public CellProcessor[] getProcessors() {
final CellProcessor[] processors = new CellProcessor[]{
new NotNull(), // COU_ID
new NotNull(), // COU_NAME
new NotNull(), // DEST_ID
new NotNull(), // DEST_NAME_DISPLAY
new Optional(), //DEST_PARENT_ID
new NotNull(), // DEST_STATION_COUNT
new NotNull(), // DEST_CHILD_DEST_COUNT
new NotNull(), // DEST_FLAG_APT
new NotNull(), // DEST_FLAG_WIN
new NotNull(), // DEST_FLAG_DEL
};
return processors;
}
【问题讨论】:
-
你的问题是……(?)
-
@AlexR “我想将列放在现有列之间,并且我想更改它们的标题(DEST_NAME_DISPLAY --> DEST_NAME_EN)。”抱歉我忘了问:我该怎么做?
-
@RichardJones DEST_NAME_DISPLAY 值不同。以阿尔巴尼亚、阿尔巴尼亚和阿尔巴尼亚为例
标签: java csv merge multiple-columns supercsv