Here you can find the source of readlines(String filename)
public static Iterable<String> readlines(String filename) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Iterator; public class Main { public static Iterable<String> readlines(String filename) throws IOException { final FileReader fr = new FileReader(filename); final BufferedReader br = new BufferedReader(fr); return new Iterable<String>() { public Iterator<String> iterator() { return new Iterator<String>() { public boolean hasNext() { return line != null; }/* w w w .j a va 2s.c o m*/ public String next() { String retval = line; line = getLine(); return retval; } public void remove() { throw new UnsupportedOperationException(); } String getLine() { String line = null; try { line = br.readLine(); } catch (IOException ioEx) { line = null; } return line; } String line = getLine(); }; } }; } }