如标题所示,超级 CSV 可以一次读取两个文件。下面的代码显示了一个 file.csv 的示例:
public class Reading {
private static final String CSV_FILENAME1 = "src/test/resources/test1/customers.csv";
public static void partialReadWithCsvMapReader() throws Exception {
ICsvMapReader mapReader1 = null;
try {
mapReader1 = new CsvMapReader(new FileReader(CSV_FILENAME1), CsvPreference.STANDARD_PREFERENCE);
mapReader1.getHeader(true);
final String[] header = new String[] { "customerNo", "firstName", "lastName", null, null, null, null, null,
null, null, "TOMEK" };
final CellProcessor[] processors = new CellProcessor[] { new UniqueHashCode(), new NotNull(),
new NotNull(), new NotNull(), new NotNull(), new Optional(), new Optional(), new NotNull(),
new NotNull(), new LMinMax(0L, LMinMax.MAX_LONG), new NotNull()};
Map<String, Object> customerMap;
while( (customerMap = mapReader1.read(header, processors)) != null ) {
System.out.println(String.format("lineNo=%s, rowNo=%s, customerMap=%s", mapReader1.getLineNumber(),
mapReader1.getRowNumber(), customerMap));
}
}
finally {
if( mapReader1 != null ) {
mapReader1.close();
}
}
}
}
一种解决方案是声明第二个变量 CSV_FILENAME2:
private static final String CSV_FILENAME1 = "src/test/resources/test1/customers.csv";
等等,但还有其他可能吗?谢谢。