Mahesh Kale

1584182272

Kotlin - How to Read CSV File in Kotlin

Kotlin, learn how to Read CSV File.

#kotlin #android #kotlinandroid #kotlincsv #tutorial

What is GEEK

Buddha Community

Kotlin - How to Read CSV File in Kotlin

How to read/write CSV file in Kotlin » grokonez

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 + "]"
}

}

  • 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

#csv #kotlin #read-file #write-file

Kotlin - How to read/write Excel file with Apache POI » grokonez

https://grokonez.com/kotlin/kotlin-read-write-excel-file-apache-poi-example

Kotlin – How to read/write Excel file with Apache POI

In this tutorial, we’re gonna look at Kotlin examples that read and write Excel file using Apache POI.

I. Dependency

<dependency>
	<groupId>org.jetbrains.kotlin</groupId>
	<artifactId>kotlin-stdlib</artifactId>
	<version>1.2.21</version>
</dependency>

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>

II. Write Data to Excel File

- Simple POJO Customer (id, name, address, age):

package com.javasampleapproach.kotlin.apachecsv

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 + "]"
}

}

  • Write to Excel file:

More at:
https://grokonez.com/kotlin/kotlin-read-write-excel-file-apache-poi-example

Kotlin – How to read/write Excel file with Apache POI

#kotlin #apache-poi #excel #read-file #write-file

Kotlin Properties - Read/Write Properties from/to .properties/.XML File - ozenero

https://ozenero.com/kotlin-properties-read-write-properties-file-properties-xml-file

Kotlin Properties – Read/Write Properties from/to .properties/.XML File

In the post, we show how to Read/Write Properties from/to .Properties/.XML files by Kotlin language.

I. Kotlin - Read/Write Properties from/to .Properties file

1. Write Properties to .Properties file
1.1 Properties store() method
We use java.util.Properties.store() methods:

// 1.
fun store(out: OutputStream, comments: String): Unit

-> Writes this property list (key and element pairs) in this Properties table 
to the output stream in a format suitable for loading into a Properties table using the load(InputStream) method.

// 2.
fun store(writer: Writer, comments: String): Unit

-> Writes this property list (key and element pairs) in this Properties table 
to the output character stream in a format suitable for using the load(Reader) method.
1.2 Kotlin Program – write Properties to .properties file

More at:

https://ozenero.com/kotlin-properties-read-write-properties-file-properties-xml-file

Kotlin Properties – Read/Write Properties from/to .properties/.XML File

#kotlin #xml #read-file #write-file

Kotlin - How to read/write CSV file with OpenCSV » grokonez

https://grokonez.com/kotlin/kotlin-how-to-read-write-csv-file-with-opencsv-example

Kotlin – How to read/write CSV file with OpenCSV

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

I. Dependency

<dependency>
	<groupId>org.jetbrains.kotlin</groupId>
	<artifactId>kotlin-stdlib</artifactId>
	<version>1.2.21</version>
</dependency>

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

II. Write Data to CSV File

1. From String Array


var fileWriter = FileWriter("customer.csv")

csvWriter = CSVWriter(fileWriter,
CSVWriter.DEFAULT_SEPARATOR,
CSVWriter.NO_QUOTE_CHARACTER,
CSVWriter.DEFAULT_ESCAPE_CHARACTER,
CSVWriter.DEFAULT_LINE_END)

val data = arrayOf(“ID”,“NAME”,“ADDRESS”,“AGE”)
csvWriter.writeNext(data)

2. From List of Objects

More at:

https://grokonez.com/kotlin/kotlin-how-to-read-write-csv-file-with-opencsv-example

Kotlin – How to read/write CSV file with OpenCSV

#kotlin #csv-file #opencsv

Juned Ghanchi

1621508255

Kotlin App Development Company in India, Hire Kotlin Developers

We are a prime Kotlin app developer in India. We build and provide the best personalized Android apps, migration services, ongoing maintenance, and management.

We have the most efficient Kotlin developers that build ultramodern, interactive, and secure mobile apps. The technologies we use to create the most advanced Kotlin apps are AR/VR, AI/ML, IoT, etc.

Hire Kotlin app developers in India. Meet us, and we will help you meet all of your technology requirements.

#kotlin app development company india #hire kotlin developers india #kotlin app development company #hire kotlin developers #kotlin development agency #kotlin app programmers