文本乱码问题
//提供一种解决C#文本乱码的解决思路
//写入使用:
string str;
str = this.menu.Text;
string fname = Application.StartupPath + "\\read.txt";
FileInfo finfo = new FileInfo(fname);
if (finfo.Exists)
{
finfo.Delete();
}
FileStream fs = new FileStream(fname,FileMode.CreateNew);
StreamWriter sw = new StreamWriter(fs,Encoding.GetEncoding("GB2312"));
//开始写入
sw.Write(str);
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
//读取采用:
string str;
StreamReader sr = new StreamReader(Application.StartupPath + "\\read.txt", Encoding.Default);
str = sr.ReadToEnd().ToString();
sr.Close();