// CSE 143, Winter 2009, Marty Stepp // This program reads integers from a file and prints them in reverse order. // // The program is an update of the program we wrote last week, but it now uses // a Java ArrayList rather than our ArrayIntList class. import java.io.*; // for File import java.util.*; // for Scanner public class ReverseFile { public static void main(String[] args) throws FileNotFoundException { // read the numbers from the file into the list ArrayList list = new ArrayList(); Scanner input = new Scanner(new File("data.txt")); while (input.hasNextInt()) { int n = input.nextInt(); list.add(n); } // print the numbers in reverse order for (int i = list.size() - 1; i >= 0; i--) { System.out.println(list.get(i)); } } }