Tries to automatically detect and set file encoding