Monday, March 07, 2005 5:56 PM | rahel luethy | 0 comment(s)

java.util.Scanner

a neat java 5 one liner to read the contents of a file into a String: String text = new Scanner(new File("foo.txt")).useDelimiter("\\A").next(); the trick is the regex \A, which matches the beginning of input and thus effectively tells Scanner to tokenize the entire stream, from beginning to (illogical) next beginning. more details can be found in pat niemeyer's original post