Print Reverse

PHOTO EMBED

Sun Jan 16 2022 05:57:04 GMT+0000 (UTC)

Saved by @mikemcnik #java

Import java.io.File;
Import java.io.FileNotFoundException;
Import java.io.PrintWriter;
Import java.lang.Integer;
Import java.util.ArrayList;
Import java.util.Scanner;

//Reads a file named "ints-in.txt" containing integers and writes the integers to "ints-out.txt" in reverse order.

Class PrintReverse {
	Public static void main (String[] args) throws FileNotFoundException {
		//Create an ArrayList of Integers
		ArrayList<Integer> list = new ArrayList<>();
		Scanner scanner = new Scanner(new File("ints-in.txt"));
		while(scanner.hasNext()){
			list.add(scanner.nextInt());
		}
		scanner.close();
		
		PrintWriter out = new PrintWriter(new File("ints-out.txt"));
		for (int I = list.size()-1; I >= 0; --i){
			out.println(list.get(i));
		}
		out.close();
	}
}
content_copyCOPY

Takes a TXT file and prints it in reverse of another TXT file.