better use apache.commons IOUtils helper methods here