C#保存txt为UTF8,去除BOM
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
Encoding encode = new System.Text.UTF8Encoding(false);
List<Class> cles = ClassService.Instance().FindAll();
FileStream stream = new FileStream(TempPath + "\\school_class.txt", FileMode.OpenOrCreate);
using (StreamWriter sw = new StreamWriter(stream, encode))
{
rt.AppendText("写入文件: school_class.txt\r\n");
string title = "id\tname";
sw.WriteLine(title);
rt.AppendText(title + "\r\n");
foreach (Class s in cles)
{
string content = s.Id + "\t" + s.Name;
sw.WriteLine(content);
rt.AppendText(content + "\r\n");
}
}
stream.Close();