fixing NPE by using the file instead of stream