나는이 예에서 수퍼 CSV website에서 dateofbirth가 선택적 열임을 보여줍니다. 두 개 이상의 선택적 열이 있으면 어떻게됩니까? 코드가 어떻게 변할 것입니까?여러 가변 열이있는 SuperCsv 사용
private static void readVariableColumnsWithCsvListReader() throws Exception {
final CellProcessor[] allProcessors = new CellProcessor[] { new UniqueHashCode(), // customerNo (must be unique)
new NotNull(), // firstName
new NotNull(), // lastName
new ParseDate("dd/MM/yyyy") }; // birthDate
final CellProcessor[] noBirthDateProcessors = new CellProcessor[] { allProcessors[0], // customerNo
allProcessors[1], // firstName
allProcessors[2] }; // lastName
ICsvListReader listReader = null;
try {
listReader = new CsvListReader(new FileReader(VARIABLE_CSV_FILENAME), CsvPreference.STANDARD_PREFERENCE);
listReader.getHeader(true); // skip the header (can't be used with CsvListReader)
while((listReader.read()) != null) {
// use different processors depending on the number of columns
final CellProcessor[] processors;
if(listReader.length() == noBirthDateProcessors.length) {
processors = noBirthDateProcessors;
} else {
processors = allProcessors;
}
final List<Object> customerList = listReader.executeProcessors(processors);
System.out.println(String.format("lineNo=%s, rowNo=%s, columns=%s, customerList=%s",
listReader.getLineNumber(), listReader.getRowNumber(), customerList.size(), customerList));
}
}
finally {
if(listReader != null) {
listReader.close();
}
}
}
옵션 열이 끝에 있지 않고 가운데 또는 다른 곳에 있으면 어떻게 될까요?