Scala 2.8 RC2 のファイル読み込み
io.Source を使いますが、ローカルファイルをファイルパスを指定して読み込む場合は fromFile だとうまくいきません。
import scala.io._ io.Source.fromFile("Test.scala")
:6: error: type mismatch;
found : java.lang.String("Test.scala")
required: java.io.File
Error occurred in an application involving default arguments.
io.Source.fromFile("Test.scala")
^
上のように、 java.io.File を使えと怒られてしまいます。ファイルパスから読み込みたい時は fromPath を使うと読めるようです。
io.Source.fromPath("Test.scala")
テキストファイルを行毎に読み込むなら、こんな感じ。
io.Source.fromPath("Test.scala").getLines("\n")
ネットワーク経由で値を読むなら、こう。
import java.net.URL import scala.io._ io.Source.fromURL(new URL("http://twitter.com/statuses/public_timeline.rss"))