Moved files and streams to try-with-resources.