📜  kotlin 逐行读取文件 - Kotlin 代码示例

📅  最后修改于: 2022-03-11 14:53:32.950000             🧑  作者: Mango

代码示例1
// Line by line
fun readFileLineByLineUsingForEachLine(fileName: String) 
  = File(fileName).forEachLine { println(it) }
// In a list of lines
fun readFileAsLinesUsingReadLines(fileName: String): List 
  = File(fileName).readLines()
// As a sole string
fun readFileDirectlyAsText(fileName: String): String 
  = File(fileName).readText(Charsets.UTF_8)