的名單,我得到了下面的方法Java的記錄器,記錄消息
public static boolean isCSVStructureValid(InputStream csv, InputStream csvSchema){
boolean failFast = true;
boolean trace = false;
Reader csvReader = new InputStreamReader(csv);
Reader csvSchemaReader = new InputStreamReader(csvSchema);
List<Substitution> pathSubtitution = new ArrayList<>();
List<FailMessage> messages = CsvValidator.validate(csvReader, csvSchemaReader, failFast,
pathSubtitution,true, trace);
if (messages.isEmpty()){
return true;
}
else{
LOGGER.log(Level.SEVERE, "The CSV stream structure is invalid: {0}", messages);
return false;
}
}
我如何才能登錄存儲列表信息中的消息的內容? 這是類型FailMessage的JavaDoc的:http://javadox.com/uk.gov.nationalarchives/csv-validator-java-api/1.0-RC2/uk/gov/nationalarchives/csv/validator/api/java/FailMessage.html
目前我得到這樣的輸出:
SEVERE: The CSV stream structure is invalid: [[email protected]27d6]
而我希望看到更多的東西有用,例如:
SEVERE: The CSV stream structure is invalid: [3.6] failure: Invalid column definition
User ID: positiveInteger
^
,我可以通過這樣做獲得:
LOGGER.log(Level.SEVERE, "The CSV stream structure is invalid: {0}", messages.get(0).getMessage());
如果你有一個'List'並且想要對每個元素執行一些操作(例如,調用'getMessage()'),那麼你將遍歷元素。你聽說過['for'loops](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html),對嗎?是的,當然你有。所以我想我不明白你在問什麼。 – Andreas
我知道,但是如何在日誌記錄中以優雅的方式來做到這一點? – user3727540
'LOGGER.log(Level.SEVERE,「CSV流結構無效:」); for(FailMessage message:messages)LOGGER.log(Level.SEVERE,「」+ message.getMessage());'?又名**循環**。 – Andreas