Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guide to scala.io and simple IO for Scala 2.9?

Does anybody have a guide to this, containing code samples, tips and an outline of the different IO approaches?

I have checked out the the API documentation. There are also some basic examples with scala.io.Source in Programming in Scala.

There are some pretty basic questions already answered here on SO.

I'm looking for something more in depth.

Alternatively, any tips on exactly which bits of the API documentation to focus on and which Java libraries? I'm familiar with System.IO in .NET land, but not so much Java.

like image 621
Nick A Miller Avatar asked Aug 11 '11 00:08

Nick A Miller


5 Answers

Scala's standard library is currently pretty limited for I/O, so you'll probably want to dig into Java's libraries. Oracle's Basic I/O tutorial, covering java.nio, looks like a reasonable starting point.

A while ago there was some discussion about a community driven redesign of Scala I/O called scala-io, but I'm not sure the official status. The mailing list hasn't seen much recent activity, but the code in Github is being actively developed (incubator mailing list and Github project). In his answer, hishadow gave a link to scala-io documentation.

like image 148
Kipton Barros Avatar answered Nov 15 '22 10:11

Kipton Barros


My tip is to look also at tools Path,File and Directory.

They have little sugar (that everyone has in their little utils library) like:

val writer = File("/my/file").bufferedWriter
File.closeQuietly(writer)
Directory("myDir").walk

Then have a look at Process like here

like image 42
Ido Tamir Avatar answered Nov 15 '22 11:11

Ido Tamir


There is an in-development IO library with documentation available at http://jesseeichar.github.com/scala-io/. Included are examples for different usages.

The source repository is at https://github.com/jesseeichar/scala-io.

like image 4
hishadow Avatar answered Nov 15 '22 11:11

hishadow


I recommend looking at java.nio.

Due to technical limitations of the underlying Java platform implementing IO in Scala wasn't a good idea.

This has changed with Java 7, which provides good Java APIs for everything related to file management.

There are some thoughts about an IO library for Scala, but no decision about that yet.

like image 2
soc Avatar answered Nov 15 '22 11:11

soc


The author of scala-IO, Jesse Eichar, has recently began a series of articles about using Scala-IO on his blog: here's the 'getting started' entry.

like image 1
ChucK Avatar answered Nov 15 '22 11:11

ChucK