Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a scala Reader from a file

Tags:

scala

How do you instantiate a scala.util.parsing.input.Reader to read from a file? The API mentions in passing something about PagedSeq and java.io.Reader, but it's not clear at all how to accomplish that.

like image 316
alejandrorm Avatar asked Oct 11 '11 00:10

alejandrorm


1 Answers

You create a FileInputStream, pass that to an InputStreamReader and pass that to the apply method of the StreamReader companion object, which returns a StreamReader, a subtype of Reader.

scala> import scala.util.parsing.input.{StreamReader,Reader}
import scala.util.parsing.input.{StreamReader, Reader}

scala> import java.io._
import java.io._

scala> StreamReader(new InputStreamReader(new FileInputStream("test")))
res0: scala.util.parsing.input.StreamReader = scala.util.parsing.input.StreamReader@1e5a0cb
like image 63
Kim Stebel Avatar answered Sep 22 '22 06:09

Kim Stebel