var s = Source.fromFile("test.txt")
var lines = s.getLines
for (line <- lines) {
println(line)
}
var arr = lines.toArray
val contents = s.mkString
for (c <- s) {
println(c)
}
val iter = s.buffered
while(iter.hasNext) {
if (iter.head ...)
处理 iter.next
else
..
}
val tokens = s.mkString.split("\\s+")
val numbers = for (w <- tokens) yield w.toDouble
或
val numbers = tokens.map(_.toDouble)
默认会自动引入scala.Console对象,因此可以使用它的方法: