import java.util.*; import java.io.*; public class ReverseFile { public static void main(String[] args) throws FileNotFoundException { File f = new File("file.txt"); reverse(new Scanner(new File("file.txt"))); } public static void reverse(Scanner input) { if (input.hasNextLine()) { // recursive case, more work to do // save first line String first = input.nextLine(); // reverse the rest of the file! reverse(input); // print first line System.out.println(first); } // implicit base case; no lines left } }