Safer reading of files with encoding