Friday, August 19, 2011

JDK7: Without streams! read file in to a list



import java.io.IOException;
import static java.nio.charset.Charset.*;
import static java.nio.file.Files.*;
import static java.nio.file.Paths.*;
import java.util.List;


public class FileReader {

    public static void read(String file) throws IOException{
        List<String> allLines = readAllLines(get(file), defaultCharset());
        for (String line : allLines) {
            System.out.println(line);
        }
    }

    public static void main(String[] args) throws IOException {
        read("./readme.txt");
    }
}