Ben Chuanlong Du's Blog

It is never too late to learn.

The Source Class in Scala IO

In [11]:
import scala.collection.JavaConverters._
Out[11]:
import scala.collection.JavaConverters._

BufferedSource

This object provides convenience methods to create an iterable representation of a source file. A BufferedSource object is iterable! Many of the collection methods apply to it.

In [2]:
val bs = scala.io.Source.fromFile("test.yaml")
Out[2]:
non-empty iterator
In [3]:
bs.mkString
Out[3]:
aa:
  - x
  - y
bb: z

InputStream to BufferedSource

In [ ]:
scala.io.Source.fromInputStream(is)
In [ ]:

Comments