Replaced resource declarations with try-with-resource statements