What\'s the Scala recipe for reading line by line from the standard input ? Something like the equivalent java code :
import java.util.Scanner;
public cla
For the console you can use Console.readLine
. You can write (if you want to stop on an empty line):
Iterator.continually(Console.readLine).takeWhile(_.nonEmpty).foreach(line => println("read " + line))
If you cat a file to generate the input you may need to stop on either null or empty using:
@inline def defined(line: String) = {
line != null && line.nonEmpty
}
Iterator.continually(Console.readLine).takeWhile(defined(_)).foreach(line => println("read " + line))