Use try-with-resources to make sure files are closed.