added try with block to autoclose stream