首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

请教如何设置字符编码

2011-12-28 
请问怎么设置字符编码.stringsLogPathsExePathIni+\\NewsList.txt System.IO.StreamWriterswMessif(!

请问怎么设置字符编码.
string   sLogPath   =   sExePathIni   +   "\\NewsList.txt ";
System.IO.StreamWriter   swMess;
if   (!System.IO.File.Exists(sLogPath))
{
swMess   =   System.IO.File.CreateText(sLogPath);
}
else
{
swMess   =   System.IO.File.AppendText(sLogPath);
}
if(txtCode.Text.Substring(0,1).Equals( "D "))
{
swMess.WriteLine(txtCode.Text   +   "01, "   +   txtMess.Text   +   "(今天) ");
swMess.WriteLine(txtCode.Text   +   "02, "   +   txtMess.Text   +   "(明天) ");
}
else
{
swMess.WriteLine(txtCode.Text   +   ", "   +   txtMess.Text);
}
swMess.Close();
如果写成
System.IO.StreamWriter   swMess   =   new   StreamWriter(sLogPath,true,Encoding.UTF8);就报错了,请问要用UTF8的方法写如应该怎么改.谢谢.

[解决办法]
string sLogPath = sExePathIni + "\\NewsList.txt ";
System.IO.StreamWriter swMess = new StreamWriter(sLogPath,false,Encoding.UTF8);
if(txtCode.Text.Substring(0,1).Equals( "D "))
{
swMess.WriteLine(txtCode.Text + "01, " + txtMess.Text + "(今天) ");
swMess.WriteLine(txtCode.Text + "02, " + txtMess.Text + "(明天) ");
}
else
{
swMess.WriteLine(txtCode.Text + ", " + txtMess.Text);
}
swMess.Close();

热点排行