Skip to content

Instantly share code, notes, and snippets.

@scottashipp
Last active January 3, 2019 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottashipp/b93f76953375cb9fc558f0c56178a941 to your computer and use it in GitHub Desktop.
Save scottashipp/b93f76953375cb9fc558f0c56178a941 to your computer and use it in GitHub Desktop.
Null variables are practically required in Java
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");
}
}
}
@scottashipp
Copy link
Author

This source code is from the official Java tutorials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment