Friday, February 13, 2009

The shortest way to read a text file

Check this out (in fact it retrieves complete web page):
new java.util.Scanner(url.openConnection().getInputStream()).useDelimiter("\\Z").next();
Thanks to CT Arrington's Weblog and Core Java Technologies Tech Tips magazine.

Update: one more short way, using Apache Commons IO:
FileUtils.readFileToString(file);

No comments:

Post a Comment