tags:

views:

443

answers:

4

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?

+5  A: 

What about using:

Source.fromInputStream(is, "UTF8")

As in:

for (line <- Source.fromInputStream(is, "UTF8").getLines) {
   // process line here
}
oxbow_lakes
Yes I knew about that but its only suitable for text/source files, its not a general IO api.
Michael Neale
@michael -you asked specifically about anything in scala to handle IO with streams. I really don't think the answer deserves the downvote. It's perfectly legitimate to use this with any underlying textual stream (eg from a socket).
oxbow_lakes
+3  A: 

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.

Walter Chang
A: 

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

Daniel
A: 

Erik Engbrecht's scalax fork might be useful.

Rafael de F. Ferreira