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 class ScannerTest {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
System.out.println(sc.nextLine());
}
}
}
The most straight-forward looking approach will just use
readLine()which is part ofPredef. however that is rather ugly as you need to check for eventual null value:this is so verbose, you’d rather use
java.util.Scannerinstead.I think a more pretty approach will use
scala.io.Source: