Montag, 22. Februar 2010

How to read from a BufferedInputStream in Scala


def bufferedInput(fileName: String) = new BufferedInputStream(new FileInputStream(fileName));

def bytesAsInts(fileName:String): Iterator[Int] = {
val in = bufferedInput(fileName)
Iterator continually in.read() takeWhile (_ != -1)
}

val file = bytesAsInts("test.txt")

file foreach(_=>printf("%c",_:Int))

// AND

file foreach(_=>printf(x=>"%c",x))


// def isNull[A] = (_: A) == null

Keine Kommentare:

Kommentar veröffentlichen