[Edit October 2019] A couple of months after I wrote this answer, Koyama Kenta wrote a Kotlin targeted library which can be found at https://github.com/doyaaaaaken/kotlin-csv and which looks much better to me than opencsv.

Example usage: (for more info see the github page mentioned)

import com.github.doyaaaaaken.kotlincsv.dsl.csvReader

fun main() {
    csvReader().open("src/main/resources/test.csv") {
        readAllAsSequence().forEach { row ->
            //Do something
            println(row) //[a, b, c]
        }
    }
}

For a complete minimal project with this example, see https://github.com/PHPirates/kotlin-csv-reader-example

Old answer using opencsv:

As suggested, it is convenient to use opencsv. Here is a somewhat minimal example:

// You can of course remove the .withCSVParser part if you use the default separator instead of ;
val csvReader = CSVReaderBuilder(FileReader("filename.csv"))
        .withCSVParser(CSVParserBuilder().withSeparator(';').build())
        .build()

// Maybe do something with the header if there is one
val header = csvReader.readNext()

// Read the rest
var line: Array<String>? = csvReader.readNext()
while (line != null) {
    // Do something with the data
    println(line[0])

    line = csvReader.readNext()
}

As seen in the docs when you do not need to process every line separately you can get the result in the form of a Map:

import com.opencsv.CSVReaderHeaderAware
import java.io.FileReader

fun main() {
    val reader = CSVReaderHeaderAware(FileReader("test.csv"))
    val resultList = mutableListOf<Map<String, String>>()
    var line = reader.readMap()
    while (line != null) {
        resultList.add(line)
        line = reader.readMap()
    }
    println(resultList)
    // Line 2, by column name
    println(resultList[1]["my column name"])
}

Dependency for Gradle: compile 'com.opencsv:opencsv:4.6' or for Gradle Kotlin DSL: compile("com.opencsv:opencsv:4.6") (as always, check for latest version in docs).

Answer from PHPirate on Stack Overflow
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ kotlin โ€บ kotlin io โ€บ read and write csv files with kotlin
Read and Write CSV Files With Kotlin | Baeldung on Kotlin
March 19, 2024 - In terms of configuration, Jackson ... CSV is good to go in just one call. The kotlin-csv library might be good for most CSV files, but it requires the strict following of the standard....
๐ŸŒ
GitHub
github.com โ€บ jsoizo โ€บ kotlin-csv
GitHub - jsoizo/kotlin-csv: Pure Kotlin CSV Reader/Writer ยท GitHub
Pure Kotlin Multiplatform CSV reader and writer.
Starred by 747 users
Forked by 52 users
Languages ย  Kotlin
๐ŸŒ
ZetCode
zetcode.com โ€บ kotlin โ€บ csv
Kotlin CSV - read, write CSV files in Kotlin
January 29, 2024 - Kotlin CSV tutorial shows how to read and write CSV files in Kotlin. We use the Opencsv and kotlin-csv libraries.
Top answer
1 of 8
21

[Edit October 2019] A couple of months after I wrote this answer, Koyama Kenta wrote a Kotlin targeted library which can be found at https://github.com/doyaaaaaken/kotlin-csv and which looks much better to me than opencsv.

Example usage: (for more info see the github page mentioned)

import com.github.doyaaaaaken.kotlincsv.dsl.csvReader

fun main() {
    csvReader().open("src/main/resources/test.csv") {
        readAllAsSequence().forEach { row ->
            //Do something
            println(row) //[a, b, c]
        }
    }
}

For a complete minimal project with this example, see https://github.com/PHPirates/kotlin-csv-reader-example

Old answer using opencsv:

As suggested, it is convenient to use opencsv. Here is a somewhat minimal example:

// You can of course remove the .withCSVParser part if you use the default separator instead of ;
val csvReader = CSVReaderBuilder(FileReader("filename.csv"))
        .withCSVParser(CSVParserBuilder().withSeparator(';').build())
        .build()

// Maybe do something with the header if there is one
val header = csvReader.readNext()

// Read the rest
var line: Array<String>? = csvReader.readNext()
while (line != null) {
    // Do something with the data
    println(line[0])

    line = csvReader.readNext()
}

As seen in the docs when you do not need to process every line separately you can get the result in the form of a Map:

import com.opencsv.CSVReaderHeaderAware
import java.io.FileReader

fun main() {
    val reader = CSVReaderHeaderAware(FileReader("test.csv"))
    val resultList = mutableListOf<Map<String, String>>()
    var line = reader.readMap()
    while (line != null) {
        resultList.add(line)
        line = reader.readMap()
    }
    println(resultList)
    // Line 2, by column name
    println(resultList[1]["my column name"])
}

Dependency for Gradle: compile 'com.opencsv:opencsv:4.6' or for Gradle Kotlin DSL: compile("com.opencsv:opencsv:4.6") (as always, check for latest version in docs).

2 of 8
9

In terms of easiness, kotlin written csv library is better.

For example, you can write code in DSL like way with below library that I created:

https://github.com/doyaaaaaken/kotlin-csv

csvReader().open("test.csv") {
    readAllAsSequence().forEach { row ->
        //Do something with the data
        println(row)
    }
}
๐ŸŒ
Kotlin
kotlinlang.org โ€บ docs โ€บ data-analysis-work-with-data-sources.html
Retrieve data from files | Kotlin Documentation
3 weeks ago - val movies = DataFrame.read("movies.csv", delimiter = ';') For a comprehensive overview of additional file formats and a variety of read functions, see the Kotlin DataFrame library documentation.
๐ŸŒ
DataFrame Help
kotlin.github.io โ€บ dataframe โ€บ read.html
Read | DataFrame
May 27, 2026 - It's included by default if you have org.jetbrains.kotlinx:dataframe:1.0.0-Beta5 already. To read a CSV file, use the .readCsv() function.
๐ŸŒ
Medium
medium.com โ€บ att-israel โ€บ jackson-csv-reader-writer-using-kotlin-f37ae771bd6d
Jackson CSV Reader/Writer Using Kotlin | by Ittay Stern | AT&T Israel Tech Blog | Medium
September 16, 2020 - Jackson CSV Reader/Writer Using Kotlin So youโ€™re writing in Kotlin and you want to load your CSV files to a List, or maybe dump your Collection to a CSV file. This is 100% reasonable, given that
Find elsewhere
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ reading-and-writing-csv-files-in-kotlin-with-apache-commons
Reading and Writing CSV Files in Kotlin with Apache Commons
February 27, 2023 - In this tutorial, we'll go over how to read and write CSV files in Kotlin, using the Apache Commons library, with examples of reading and writing custom objects.
๐ŸŒ
DEV Community
dev.to โ€บ blackmo18 โ€บ kotlin-csv-kotlin-grass-2b8j
Kotlin CSV to Data Class Parser - DEV Community
December 31, 2021 - It requires another awesome Kotlin library for reading the CSV, namely Kotlin-CSV.
๐ŸŒ
Floern
floern.com
CSV in Kotlin with Casting CSV โ€“ floern.com;;
Introduction and deep dive into Casting CSV, my open source Kotlin library to automagically read and write CSV with a one-liner using Kotlin data classes and reflection.
๐ŸŒ
DEV Community
dev.to โ€บ zion_onwujuba_894fe00cd83 โ€บ reading-a-csv-using-opencsv-and-kotlin-d02
Reading a CSV using OpenCSV and Kotlin - DEV Community
August 8, 2024 - In this article, we will learn how we can use the free Java library, OpenCSV, to read a CSV and populate a Kotlin class with the data from the CSV.
๐ŸŒ
MojoAuth
mojoauth.com โ€บ parse-and-generate-formats โ€บ parse-and-generate-csv-with-kotlin
Parse and Generate CSV with Kotlin | Parse and Generate Formats
September 12, 2025 - Such libraries might not support modern CSV features or could harbor unaddressed bugs. Many libraries simplify header management. You can often configure them to automatically recognize and use the first row as headers, allowing you to access data by column name instead of index. import com.github.doyaaaaen.kotlin.csv.core.CsvReader val reader = CsvReader { header = true } val records = reader.read(File("data.csv")) records.forEach { row -> val name = row["Name"] println("Name: $name") }
๐ŸŒ
GitHub
github.com โ€บ PHPirates โ€บ kotlin-csv-reader-example
GitHub - PHPirates/kotlin-csv-reader-example: Example of how to read a csv line by line in Kotlin.
Example of how to read a csv line by line in Kotlin. - PHPirates/kotlin-csv-reader-example
Starred by 2 users
Forked by 2 users
Languages ย  Kotlin 100.0% | Kotlin 100.0%
๐ŸŒ
Kotlin
kotlinandroid.org โ€บ kotlin android home โ€บ kotlin tutorials โ€บ kotlin file operations โ€บ kotlin โ€“ read csv file
Kotlin โ€“ Read CSV File
To reading a CSV (Comma-Separated Values) file in Kotlin efficiently, you can use basic file reading functions along with string manipulation methods.
๐ŸŒ
DataFrame Help
kotlin.github.io โ€บ dataframe โ€บ csv-tsv.html
CSV / TSV | DataFrame
Work with CSV and TSV files โ€” read, analyze, and export tabular data using Kotlin DataFrame.
๐ŸŒ
GitHub
github.com โ€บ kotools โ€บ csv
GitHub - kotools/csv: Elegant CSV file's manager for Kotlin. ยท GitHub
November 3, 2022 - Kotools CSV is a lightweight library for managing CSV files with elegant Kotlin DSLs.
Author ย  kotools
๐ŸŒ
Gitbook
kenta-koyama-biz.gitbook.io โ€บ kotlin-csv
README | kotlin-csv
January 20, 2024 - - CANONICAL: Not quote normally, but quote special characters (quoteChar, delimiter, line feed). This is the specification of CSV. - ALL: Quote all fields. - NON_NUMERIC: Quote non-numeric fields. (ex. 1,"a",2.3) ... Contributions, issues and feature requests are welcome! If you have questions, ask away in Kotlin Slack's kotlin-csv room.
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ parsing-table-data-in-kotlin-2 โ€บ lessons โ€บ working-with-csv-files-in-kotlin
Working with CSV Files in Kotlin
This lesson builds on your existing knowledge of file parsing in Kotlin and introduces techniques that will enhance your data handling capabilities using Kotlin's expressive syntax. ... CSV (Comma-Separated Values) is a format used to store tabular data in plain text.
๐ŸŒ
GitHub
github.com โ€บ sergejsha โ€บ csv
GitHub - sergejsha/csv: Tiny Kotlin Multiplatform library for parsing and building CSV strings ยท GitHub
A tiny, fast Kotlin Multiplatform library for parsing and building CSV strings.
Starred by 21 users
Forked by 3 users
Languages ย  Kotlin