This can be achieved in a single line using IOUtils