Created
September 18, 2012 23:14
-
-
Save seamusabshere/3746658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package java112.labs1; | |
import java.io.*; | |
public class LabSix { | |
public static void main(String[] arguments) { | |
if (arguments.length != 2) { | |
System.out.println("Please enter two arguments on the command line, an input file name and an output file name"); | |
} else { | |
LabSix lab = new LabSix(); | |
lab.run(arguments[0], arguments[1]); | |
} | |
} | |
public void run(String inputFilePath, String outputFilePath) { | |
BufferedReader in = null; | |
PrintWriter out = null; | |
try { | |
// this requires catching FileNotFoundException | |
in = new BufferedReader(new FileReader(inputFilePath)); | |
// this requires catching IOException | |
out = new PrintWriter(new BufferedWriter(new FileWriter(outputFilePath))); | |
mirrorFile(in, out); | |
} catch (FileNotFoundException fileNotFoundException) { | |
fileNotFoundException.printStackTrace(); | |
} catch (IOException ioException) { | |
ioException.printStackTrace(); | |
} finally { | |
if (in != null) { | |
try { | |
// this requires catching IOException | |
in.close(); | |
} catch (IOException ioException) { | |
ioException.printStackTrace(); | |
} | |
} | |
if (out != null) { | |
out.close(); | |
} | |
} | |
} | |
public void mirrorFile(BufferedReader in, PrintWriter out) { | |
try { | |
while (in.ready()) { | |
out.println(in.readLine()); | |
} | |
} catch (IOException ioException) { | |
ioException.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment