import java.util.*; import java.io.*; /* Printing out the contents of the file "lyrics.txt" * line by line, but with the lines reversed */ public class ReverseFile { public static void main(String[] args) throws FileNotFoundException { Scanner fileScan = new Scanner(new File("lyrics.txt")); /* String[] words = new String[100]; // Is 100 spots enough?? int numWords = 0; while(fileScan.hasNextLine()) { words[numWords] = fileScan.nextLine(); numWords++; } for(int i = numWords - 1; i>= 0; i--) { System.out.println(words[i]); } */ ArrayList words = new ArrayList(); while(fileScan.hasNextLine()) { words.add(fileScan.nextLine()); } for (int i = words.size() - 1; i >= 0; i--) { System.out.println(words.get(i)); } } }