// Erika Wolfe // CSE 143, Section ZZ // TA: Stuart Reges // This program reads in a file and prints out the lines 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("words.txt")); // We decided to use a Stack for this problem instead of an // ArrayList. The ArrayList fit the problem better than an // array, but a Stack works even better. See 06/18 for original. // First read in lines Stack allLines = new Stack(); while (input.hasNextLine()) { String line = input.nextLine(); allLines.push(line); } // Print in reverse // Using a Stack makes this so clean! while (!allLines.isEmpty()) { System.out.println(allLines.pop()); } } }