[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 this tutorial, we parsed and wrote CSV with various methods. We can use pure Kotlin with only standard libraries to write a parser that won’t change much during the life of our software.
🌐
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
🌐
DEV Community
dev.to › blackmo18 › kotlin-csv-kotlin-grass-2b8j
Kotlin CSV to Data Class Parser - DEV Community
December 31, 2021 - Let's get back to my Kotlin-Grass, a CSV to data class parser.
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)
    }
}
🌐
DataFrame Help
kotlin.github.io › dataframe › read.html
Read | DataFrame
May 27, 2026 - val df = DataFrame.readCsv( file, parserOptions = ParserOptions( dateTime = DateTimeParserOptions.Kotlin.withFormat( LocalDate.Format { monthNumber(padding = Padding.SPACE); char('/'); day(); char(' '); year() }, ), ), ) These two approaches are essentially the same, just specified in different ways. The result will be a dataframe with properly parsed DateTime columns. Note: Although these examples focus on reading CSV files, these ParserOptions can be supplied to any String-column-handling operation (like, readCsv, readTsv, stringCol.convertTo<>(), etc.)
🌐
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.
🌐
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
🌐
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") }
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.
🌐
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.
🌐
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
🌐
Kotlin
kotlinandroid.org › kotlin android home › kotlin tutorials › kotlin file operations › kotlin – read csv file
Kotlin – Read CSV File
import java.io.File fun main() { val filePath = "dir1/data.csv" // Replace with your CSV file path val file = File(filePath) file.forEachLine { line -> val tokens = line.split(",") // Process tokens here println(tokens) } }
🌐
SSOJet
ssojet.com › parse-and-generate-formats › parse-and-generate-csv-in-kotlin
Parse and Generate CSV in Kotlin | Parse and Generate Formats in Popular Programming Languages
Reading CSV data into your Kotlin application is straightforward using established Java libraries. Apache Commons CSV is a popular choice, allowing you to parse CSV files directly into memory, often as a list of records or mapped to custom data ...
🌐
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%
🌐
CodeSignal
codesignal.com › learn › courses › parsing-table-data-in-kotlin-2 › lessons › working-with-csv-files-in-kotlin
Working with CSV Files in Kotlin
Understanding how CSV files are structured is crucial for effectively parsing the data in your programming environment. ... Using Kotlin's standard library, we can efficiently read and parse CSV files.
🌐
Kotlinlang
slack-chats.kotlinlang.org › t › 16758697 › are-there-any-csv-parsing-libraries-on-kotlin-multiplatform-
Are there any CSV parsing libraries on Kotlin Multiplatform kotlinlang #multiplatform
March 22, 2024 - The most popular one I've got into is Kotlin-CSV (https://github.com/doyaaaaaken/kotlin-csv) but it lacks Native support.
🌐
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.
🌐
SSOJet
ssojet.com › serialize-and-deserialize › serialize-and-deserialize-csv-in-kotlin
Serialize and Deserialize CSV in Kotlin | Serialize and Deserialize Data in Programming Languages
December 13, 2025 - Parsing CSV data into structured Kotlin objects is significantly simplified by using dedicated libraries. Instead of manually splitting strings and managing column indices, libraries like kotlinx-serialization-csv allow you to map CSV rows directly ...
🌐
YouTube
youtube.com › dmitry kandalov
Test driving CSV parser in Kotlin - YouTube
In this pair programming session Duncan and I test drive a CSV parser (a CSV "table reader" to be precise) from scratch following the steps from the upcoming...
Published   December 31, 2020
Views   982