Use try-with-resource instead of try-finally to close stream, and merge two try blocks into one. This looks more concise.