Tuesday, January 16, 2007

java.util.Scanner oops!

Java 5 java.util.Scanner provides a better replacement for StringTokenizer. And, the hope was that we should be able to write,

Scanner lines = new Scanner(new File("/etc/passwd"));
for(String line : lines) {
System.out.println(line);
}

Unfortunately, this doesn't work because someone mistyped, and it implements Iterator instead of Iterable.