what's the right way to use scala.io.Source?

Posted by woods on Stack Overflow See other posts from Stack Overflow or by woods
Published on 2010-12-16T08:45:58Z Indexed on 2010/12/22 1:54 UTC
Read the original article Hit count: 508

Filed under:
|

In many examples, it is described that you can use scala.io.Source to read a whole file like this:

val str = scala.io.Source.fromFile("test.txt").mkString()

But closing the underlying stream is not mentioned. Why does Scala not provide a convenient way to do that such as with clause in Python? It looks useful but not difficult.

Is there any other better way to do that safely in Scala, i means to read a whole file?

© Stack Overflow or respective owner

Related posts about scala

Related posts about scala-2.8