Encoding code = Encoding.UTF8; TextWriter sw = new StreamWriter(path, true, code); sw.WriteLine(content);
以上代码在Windows执行写入文件没有出现乱码问题,但是在Linux下开头回出现乱码,文件格式为UTF8-BOM格式
按照下面得方式修改后即可。
Encoding code = new System.Text.UTF8Encoding(false); TextWriter sw = new StreamWriter(path, true, code); sw.WriteLine(content);
转载https://github.com/dotnet/aspnetcore/issues/10029
标签:StreamWriter,code,Encoding,sw,乱码,new,txt From: https://www.cnblogs.com/wangjunguang/p/16627309.html