Improved code to use the try-with-resources construct instead of closing all InputStream and Reader manually.