0
下面的代碼解析了CSV記錄,如果標頭總是事先知道,我們可以爲FILE_HEADER_MAPPING聲明數組值。動態標頭CSVParser
CSVFormat csvFileFormat = CSVFormat.DEFAULT.withHeader(FILE_HEADER_MAPPING);
FileReader fileReader = new FileReader("file");
CSVParser csvFileParser = new CSVParser(fileReader, csvFileFormat);
Iterable<CSVRecord> records = csvFileParser.getRecords();
但是如何爲每個csv文件的頭文件不同的CSV文件創建CSVParser。
我不知道CSV文件的標題來創建格式
CSVFormat csvFileFormat = CSVFormat.DEFAULT.withHeader(FILE_HEADER_MAPPING);
我想爲每一個可能的CSV頭一個CSV解析器。 請幫我解決這個情況。
我想這是apache commons CSV解析器? – JoSSte
是的,它是apache csv分析器。 – Sharan
您是否閱讀過有關標題自動檢測的內容? 這可能可能解決您的問題: https://commons.apache.org/proper/commons-csv/user-guide.html#Header_auto_detection – JoSSte