L09 - ReverseIt Lab
Write a program that reads in a file and writes each line backwards to an output file. Below is a skeleton of the program. Fill in the blanks with the missing code.
/**
* Reverses each line of an input file and writes it to an output file.
*
* @author ______
* @version ______
*/
import java.util.*;
import java._____.*;
public class ReverseIt {
public static void main(String[] args) throws _____, _____ {
Scanner myScanner = new Scanner(System.in);
System.out.print("Enter input filename: ");
String inFilename = myScanner.nextLine();
System.out.print("Enter output filename: ");
String outFilename = myScanner.nextLine();
FileReader inReader = new FileReader(______);
PrintWriter outWriter = new PrintWriter(______);
Scanner inputFile = new Scanner(______);
while (inputFile.hasNext()) {
String inString = ______.nextLine();
String outString = "";
for (int i = 0; i < ______.length(); i++)
outString = ______.charAt(i) + outString;
outWriter.println(______);
}
______.close();
______.close();
System.out.println("Goodbye!");
}
}
Sample Dialog
Enter input filename: ReverseIt.java
Enter output filename: sdrawkcaB.txt
Goodbye!
No Comments