// CSE 143, Winter 2009, Marty Stepp // This program reads integers from a file and prints them in reverse order // using our new 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 ArrayIntList list = new ArrayIntList(); Scanner input = new Scanner(new File("data.txt")); while (input.hasNextInt()) { int n = input.nextInt(); list.add(n); } // list.add(0, 424242); // print the numbers in reverse order for (int i = list.size() - 1; i >= 0; i--) { System.out.println(list.get(i)); } } }