Scala file slurp

scala

Solution

File isn't part of the stdlib anymore. Instead you should use `scala.io.Source`. To read an entire file you can do

val fileContents = io.Source.fromFile("my_file.txt").mkString

this should be avoided for large files though. In case of large files use `Source.getLines` instead and process the file line by line. `Source` also has a lot of other handy methods, so check them here http://www.scala-lang.org/api/current/index.html#scala.io.Source

Problem

On this question Read entire file in Scala? there is a comment to the first answer that reads but I'd hate for people not to know they can do "io.File("/etc/passwd").slurp" in trunk. When I try to do that, scala tells me ``` error: object File is not a member of package io ``` I have scala 2.9.1-1. Am I doing something wrong?

Original source

Related problems