将字符串写入htm文件后中文成乱码!请各位帮帮忙啊!
private void ReadHtml()
{
StreamReader sr = new StreamReader("C:\\Inetpub\\wwwroot\\OnlineShop\\Foot.htm",System.Text.Encoding.GetEncoding("GB2312"));
string StrHtml = sr.ReadToEnd();
this.Content.Value = StrHtml;
sr.Close();
}
private void BtnOK_Click(object sender, System.EventArgs e)
{
string StrHtml = this.Content.Value;
FileInfo f = new FileInfo("C:\\Inetpub\\wwwroot\\OnlineShop\\Foot.htm");
using(FileStream fs = f.OpenWrite())
{
StreamWriter sw = new StreamWriter(fs,System.Text.Encoding.GetEncoding("GB2312"));
fs.Close();
sw = f.CreateText();
sw.WriteLine(StrHtml);
sw.Close();
}
}
将foot.htm的文件读出来在写回到foot.htm中,中文就变成了乱码,在设断点监视的时候发现变量StrHtml有很多类似/t/n之内的标记。这些标记在我原文件中是没有的,是不是跟这有关??请高手指教一二,小弟不胜感激!!!