Handled unclosed resources using try-with-resources statement