DEV Community

loizenai
loizenai

Posted on

How to read/write CSV file in Kotlin

https://grokonez.com/kotlin/kotlin-read-write-csv-file-example

How to read/write CSV file in Kotlin

In this tutorial, we're gonna look at examples that read and write CSV file using native Kotlin.

I. Write Data to CSV File

  • Simple POJO Customer (id, name, address, age):
    
    package com.javasampleapproach.kotlin.csv

class Customer {
var id: String? = null
var name: String? = null
var address: String? = null
var age: Int = 0

constructor() {}
constructor(id: String?, name: String?, address: String?, age: Int) {
    this.id = id
    this.name = name
    this.address = address
    this.age = age
}

override fun toString(): String {
    return "Customer [id=" + id + ", name=" + name + ", address=" + address + ", age=" + age + "]"
}
Enter fullscreen mode Exit fullscreen mode

}

  • Write Customer List to CSV file:

More at:

https://grokonez.com/kotlin/kotlin-read-write-csv-file-example

How to read/write CSV file in Kotlin

Top comments (0)