Monday 26 July 2010

How 2 read a textfile the easy way

Reading in a text file should be so easy. However Java's designers went a bit nuts with the decorator pattern. Fortunately commons.IO makes life easier:

http://commons.apache.org/io/api-release/index.html

Has this lovely method:

public static String readFileToString(File file)


also of note:

public static byte[] readFileToByteArray(File file)
public static String readFileToString(File file, String encoding)

No comments:

Post a Comment