I came across this question and am looking for some ideas?
Try-with-resources is available as of Java 1.7
Anything that inherits from Closeable
or Autocloseable
can use it.
https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
try (FileReader br = new FileReader(path)) {
return br.readLine();
}
This will automatically call a close
function which is guaranteed to be called at the end of the block.