Updated file handling

We now use try-with-resources more consistently.