// Program to print out a file line-by-line in reverse order // using recursion. import java.util.*; import java.io.*; public class ReverseFile { public static void main(String[] args) throws FileNotFoundException { Scanner console = new Scanner(System.in); System.out.print("File name? "); String fileName = console.nextLine(); Scanner input = new Scanner(new File(fileName)); reverse(input); } public static void reverse(Scanner input) { if (input.hasNextLine()) { // read first line String line = input.nextLine(); // reverse the rest of the file (recursive call) reverse(input); // print first line System.out.println(line); } // implicit base case -- do nothing (mic drop) } }