所以最好的办法将其转换为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;
}
{
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;
}