Using try with resources to facilitate closing and small changes