Kotlin read file with File.readLines

File.readLines() reads the file content as a list of lines. It should not be used for large files.

Kotlin read a file with File.readLines

The example reads a file with File.readLines().
import java.io.File

fun main(args: Array<String>) {

    val fileName = "src/resources/sample.txt"
    val lines: List<String> = File(fileName).readLines()
    lines.forEach { line -> println(line) }

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course