Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idiomatic IO with scala

Tags:

jvm

scala

In java, common IO operations involving streams, files and the like can be somewhat annoying. Thus I (and many others) tend to reach for things like commons-io to ease the pain.

In scala - are there some better idioms/classes/libraries to use (I know of scala.io.Source etc for reading in text files - but what about streams etc). Is it "normal" to use libraries like commons-io in scala or is there a much better way?

like image 978
Michael Neale Avatar asked Oct 20 '09 10:10

Michael Neale


3 Answers

What about using:

Source.fromInputStream(is, "UTF8")

As in:

for (line <- Source.fromInputStream(is, "UTF8").getLines) {
   // process line here
}
like image 74
oxbow_lakes Avatar answered Nov 04 '22 18:11

oxbow_lakes


There were some discussions on the Scala mailing list on this particular matter. And, if I recall correctly, nothing concrete came out of them. In the mean time, you won't be at a loss to check out Scalax. scalax.io looks very promising.

like image 25
Walter Chang Avatar answered Nov 04 '22 19:11

Walter Chang


I/O hasn't been addressed as yet in Scala. What exists, exists solely to support the compiler and the XML library.

like image 1
Daniel C. Sobral Avatar answered Nov 04 '22 18:11

Daniel C. Sobral