Created
December 10, 2014 13:05
-
-
Save why-jay/0a31ac34200667464469 to your computer and use it in GitHub Desktop.
Resource release in finally
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
// borrowed from docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html | |
static String readFirstLineFromFileWithFinallyBlock(String path) throws IOException { | |
BufferedReader br = new BufferedReader(new FileReader(path)); | |
try { | |
return br.readLine(); | |
} finally { | |
if (br != null) br.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment