Created
September 20, 2011 21:07
-
-
Save ejknapp/1230342 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.*; | |
/** | |
* @author Eric Knapp | |
* class DemoIoTwo | |
* | |
*/ | |
public class DemoIoTwo { | |
private static final int COMMAND_ARGUMENTS_COUNT_WITH_FILE_NAME = 2; | |
public void run(String[] arguments) { | |
if (arguments.length != COMMAND_ARGUMENTS_COUNT_WITH_FILE_NAME) { | |
System.out.println("Hey! Add a file name."); | |
return; | |
} | |
BufferedReader input = null; | |
try { | |
input = new BufferedReader(new FileReader(arguments[0])); | |
displaySomeLines(input); | |
} catch (java.io.FileNotFoundException notFound) { | |
notFound.printStackTrace(); | |
} catch (IOException ioException) { | |
ioException.printStackTrace(); | |
} catch (Exception exception) { | |
exception.printStackTrace(); | |
} finally { | |
try { | |
if (input != null){ | |
input.close(); | |
} | |
} catch (Exception exception) { | |
exception.printStackTrace(); | |
} | |
} | |
} | |
private void displaySomeLines(BufferedReader input) | |
throws IOException, Exception { | |
String line = null; | |
while (input.ready()) { | |
line = input.readLine(); | |
System.out.println(line); | |
} | |
} | |
public static void main(String[] args) { | |
DemoIoTwo lab = new DemoIoTwo(); | |
lab.run(args); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment