Answers for "kotlin file read line"

1

kotlin read file line by line

// Line by line
fun readFileLineByLineUsingForEachLine(fileName: String) 
  = File(fileName).forEachLine { println(it) }
// In a list of lines
fun readFileAsLinesUsingReadLines(fileName: String): List<String> 
  = File(fileName).readLines()
// As a sole string
fun readFileDirectlyAsText(fileName: String): String 
  = File(fileName).readText(Charsets.UTF_8)
Posted by: Guest on April-21-2021

Browse Popular Code Answers by Language