Java tutorial
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Main { public static void main(String... args) throws IOException { String oneLine = processFile((BufferedReader b) -> b.readLine()); System.out.println(oneLine); String twoLines = processFile((BufferedReader b) -> b.readLine() + b.readLine()); System.out.println(twoLines); } public static String processFile(BufferedReaderProcessor p) throws IOException { try (BufferedReader br = new BufferedReader(new FileReader("lambdasinaction/chap3/data.txt"))) { return p.process(br); } } } interface BufferedReaderProcessor { public String process(BufferedReader b) throws IOException; }