Java tutorial
import java.io.BufferedReader; import java.io.FileReader; public class Main { public static void main(String[] args) throws Exception { String first, last = null, line; BufferedReader in = new BufferedReader(new FileReader(args[0])); first = in.readLine(); while ((line = in.readLine()) != null) { if (line != null) { last = line; } } System.out.println(first + "\n" + last); in.close(); } }