请问怎么设置字符编码.
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();