import java.io.*; import java.util.*; public class EditorDriver { protected Editor editor; protected BufferedReader fileReader; protected PrintWriter fileWriter; /** * Initializes this EditorDriver object. */ public EditorDriver() { editor = new Editor(); } //constructor /** * Reads in the file paths, declares and opens the input and output files * * @return a reference to the file writer * */ public PrintWriter openFiles() { final String IN_FILE_PROMPT = "\n\nPlease enter the path for the input file: "; final String OUT_FILE_PROMPT = "\n\nPlease enter the path for the output file: "; final String IO_EXCEPTION_MESSAGE = "The file was not found.\n\n"; BufferedReader keyboardReader = new BufferedReader (new InputStreamReader (System.in)); String inFilePath, outFilePath; boolean pathsOK = false; while (!pathsOK) { try { System.out.print (IN_FILE_PROMPT); inFilePath = keyboardReader.readLine(); fileReader = new BufferedReader (new FileReader (inFilePath)); System.out.print (OUT_FILE_PROMPT); outFilePath = keyboardReader.readLine(); fileWriter = new PrintWriter (new FileWriter (outFilePath)); pathsOK = true; } // try catch (IOException e) { System.out.println (IO_EXCEPTION_MESSAGE + e); } // catch I/O exception } // while return fileWriter; } // method openFiles /** * Creates the output file by performing the input-file commands. * */ public void editText() { String line = new String(), result = new String(); while (true) { try { line = fileReader.readLine(); if (line == null) break; fileWriter.println (line); result = editor.interpret (line); } // try catch (RuntimeException e) { fileWriter.println (e); } // catch RuntimeException catch (IOException e) { System.out.println (e); } // catch IOException if (line.equals (Editor.DONE_COMMAND)) fileWriter.println (result); } // while } // method editText } // class EditorDriver