黑猴子的家:Scala 读取行

案例

import scala.io.Source

object FileSyllabus {
  def main(args: Array[String]): Unit = {
    val buffered_Source1 = Source.fromFile("E:\\ scala_project\\2019.log", "UTF-8")
    val lines = buffered_Source1.getLines()
    for (line <- lines){
      println(line)
    }
    buffered_Source1.close
  }
}

文件内容转数组

val array= buffered_Source1.getLines.toArray

文件内容转字符串

val iterator = buffered_Source1.mkString

转载于:https://www.jianshu.com/p/d4e8c39e111d

猜你喜欢

转载自blog.csdn.net/weixin_33690963/article/details/91182540