关于这个问题
对于第一个答案,有一个评论是:
,但我不想让人们不知道他们可以在主干中做“io.File(”/etc/passwd“).slurp。
当我尝试这样做的时候,scala告诉我
error: object File is not a member of package io我有斯卡拉2.9.1-1。我做错了什么吗?
发布于 2012-06-15 10:42:50
文件不再是stdlib的一部分了。相反,您应该使用scala.io.Source。若要读取整个文件,请执行以下操作
val fileContents = io.Source.fromFile("my_file.txt").mkString但是,对于大型文件来说,应该避免这种情况。在大文件的情况下,使用Source.getLines代替并逐行处理文件。Source还有许多其他方便的方法,所以在这里查看它们,http://www.scala-lang.org/api/current/index.html#scala.io.Source
https://stackoverflow.com/questions/11047256
复制相似问题