// CSE 143, Winter 2010, Marty Stepp // This program uses recursion to print the lines of a file in reverse order. import java.io.*; import java.util.*; public class ReverseFile { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("poem.txt")); reverseLines(input); } // Prints the lines of the given input file in reverse order, recursively. public static void reverseLines(Scanner input) { String line = input.nextLine(); // line 1 of 4 if (!input.hasNextLine()) { // base case System.out.println(line); } else { // recursive case reverseLines(input); System.out.println(line); } } }