Last active
January 3, 2019 14:53
-
-
Save scottashipp/b93f76953375cb9fc558f0c56178a941 to your computer and use it in GitHub Desktop.
Null variables are practically required in Java
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
public void writeList() { | |
PrintWriter out = null; | |
try { | |
System.out.println("Entering" + " try statement"); | |
out = new PrintWriter(new FileWriter("OutFile.txt")); | |
for (int i = 0; i < SIZE; i++) { | |
out.println("Value at: " + i + " = " + list.get(i)); | |
} | |
} catch (IndexOutOfBoundsException e) { | |
System.err.println("Caught IndexOutOfBoundsException: " | |
+ e.getMessage()); | |
} catch (IOException e) { | |
System.err.println("Caught IOException: " + e.getMessage()); | |
} finally { | |
if (out != null) { | |
System.out.println("Closing PrintWriter"); | |
out.close(); | |
} | |
else { | |
System.out.println("PrintWriter not open"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This source code is from the official Java tutorials