By all accounts, Scala's Source
is a bit of a mess - everything I've read about it mentions resources left open, mysterious bugs...
I was wondering whether that was still the case in recent versions of Scala and, if so, what are worthy alternatives?
I've mostly heard of scala-io and scalaz-streams (and, obviously standard Java IO primitives). Did I miss anything? If anyone has experience with these or other projects, what are their respective pros and cons?
I'm inclined to go for scala-io
, since I found the author's blog to be a fairly high quality source of useful of information, but I'd love to know more about the alternatives and what other people use.
Rapture IO might be worth trying.
It provides some nice DSL for managing IO resources of various kinds.
Using the package java.nio.file
in Java standard library may also be simple enough if you don't require advance features. For example, to read the lines of a file into memory:
Files.readAllLines(Paths.get("file_name"), StandardCharsets.UTF_8).asScala
And to write a sequence of lines into a file:
val strs = Seq("line1", "line2", "line3") Files.write(Paths.get("output_file"), strs.mkString("\n").getBytes())
Check http://docs.oracle.com/javase/tutorial/essential/io/file.html for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With