【发布时间】:2018-03-23 09:47:33
【问题描述】:
我正在尝试通过 scala 命令行读取文本文件。 代码编译正确,但由于找不到文件错误而导致执行失败。
import scala.io.Source
object Mainclass extends App {
val filename = "filo.txt"
for(line <- Source.fromFile(filename).getLines) {
println(line)
}
}
这是错误:
scala Main.scala:
java.io.FileNotFoundException: filo.txt (The system cannot find the file specified)
【问题讨论】:
-
您的代码对我来说运行没有错误(在我创建了
filo.txt文件之后)。
标签: scala user-defined-functions scala-collections