Resource handling with try-with-resources