/* * Kyle Pierce * CSE 143 * * Reads from "words.txt" and prints the lines of that file * in the reverse order from what is in the file */ 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")); /* * ArrayList code from last Monday * * ArrayList lines = new ArrayList(); * while (input.hasNextLine()) { * String line = input.nextLine(); * lines.add(line); * } * * for (int i = lines.size() - 1; i >= 0; i--) { * System.out.println(lines.get(i)); * } */ Stack lines = new Stack(); while (input.hasNextLine()) { String line = input.nextLine(); lines.push(line); } while (!lines.isEmpty()) { System.out.println(lines.pop()); } } }