cloud9_note

cloud9に限らないメモ

View on GitHub

Opencsv

pom.xml

<dependency>
    <groupId>com.opencsv</groupId>
    <artifactId>opencsv</artifactId>
    <version>5.9</version>
</dependency>

行単位で読み込む

try (CSVReader csvReader = new CSVReader(new InputStreamReader(new FileInputStream(this.csvPath.toString()), charset))) {
    return
        csvReader.readAll() // readAllの戻り値はList<String[]>。
                 .stream() 
                 .skip(1) // ヘッダ行を読み飛ばす
                 // 任意の終端処理
} catch (CsvException | IOException e) {
    logger.error(e);
    throw e;
}