可能的原因是你的文本文件的Encoding是gb2312的.而.Net 读文文件的缺省Encoding是UTF8
所以最好的办法将其转换为utf8. 下面是代码片断
while(true)
{
System.Windows.Forms.OpenFileDialog dialog 
= new OpenFileDialog();
dialog.Filter 
= "cs file|*.cs|all file|*.*";
dialog.Multiselect 
= false;
if(dialog.ShowDialog(this== DialogResult.OK)
{
    string fileName = dialog.FileName;
    System.IO.StreamReader sr 
= new System.IO.StreamReader(fileName ,System.Text.Encoding.GetEncoding(936));
   
string line = sr.ReadToEnd();
    sr.Close();
    System.IO.StreamWriter SW = new System.IO.StreamWriter(fileName ,false,System.Text.UTF8Encoding.UTF8);   
   if(line != null)
    {
        SW.Write(line);

    }
    SW.Close();
}
else
    break;
}


posted on 2006-06-26 13:54  Shark Xu  阅读(966)  评论(0编辑  收藏  举报
为汶川地震死难者哀悼!