The following text was written to the standard output stream when the Reverse program was executed from Netbeans.
/* *ThisprogramfeaturesanArrayListtodoitsreversecopythingfromonefiletoanother. */ package arraylistplay; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Scanner; /** * * * @author dmaslows */ public class ReverseCopyLyrics { /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException, IOException { String inputR = "R.text"; String outputR = "RReversed.text"; ArrayListwords = readWordsFromR(inputR); writeWordsToR(words, outputR); } private static ArrayList readWordsFromR(String inputR) throws FileNotFoundException { // Equate a scanner with the input file Scanner scanner = establishScanner(inputR); // Read the words from the file into a dynamically growing ArrayList ArrayList words = new ArrayList<>(); while(scanner.hasNext()){ String word = scanner.next(); words.add(word); } return words; } private static void writeWordsToR(ArrayList words, String outputR) throws FileNotFoundException { try ( PrintWriter printer = getPrintWriter(outputR)) { for (int x = words.size() - 1; x>=0; x=x-1){ printer.println(words.get(x)); } } } private static Scanner establishScanner(String inputR) throws FileNotFoundException { String fullR = createFullR(inputR); return new Scanner(new File(fullR)); } private static PrintWriter getPrintWriter(String outputR) throws FileNotFoundException { String fullR = createFullR(outputR); PrintWriter printer = new PrintWriter(fullR); return printer; } private static String createFullR(String R) { String separator = System.getProperty("file.separator"); String home = System.getProperty("user.home"); String path = home + separator + "CS1Files" + separator + "data" + separator; String fullR = path + R; return fullR; } }