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[] arr = new String[100]; int index = 0; while(fileScan.hasNextLine()) { String line = fileScan.nextLine(); arr[index] = line; index++; } for(int i = index - 1; i >= 0; i--) { System.out.println(arr[i]); } */ ArrayList list = new ArrayList(); while(fileScan.hasNextLine()) { String line = fileScan.nextLine(); list.add(line); } for(int i = list.size() - 1; i >= 0; i--) { System.out.println(list.get(i)); } } }