Change Text File Encoding
问题 How do you change a text files encoding through code? I am using this code to actually create the file itself, but how can I change the encoding (change to UTF-8 w/o BOM) string path = @"E:\Test\Example.txt"; if (!File.Exists(path)) { File.Create(path); } 回答1: You could do something like that, but I'm not sure this makes really sense, as it seems you have no content in your file... If you have a content, replace string.Empty by the content File.WriteAllText(path, string.Empty, Encoding