Use try-with-resources where appropriate

This is more succinct and idiomatic Java style.
Does this handle arrays nicely?