字符编码
Encoding gb = Encoding.GetEncoding("GB2312"); byte[] bytes = System.IO.File.ReadAllBytes("gb.txt"); string str = gb.GetString(bytes); Console.WriteLine(str); byte[] utfBytes = Encoding.UTF8.GetBytes(str); System.IO.File.WriteAllBytes("utf.txt", utfBytes); Console.WriteLine("finished"); Console.ReadLine();
Encoding ansi = Encoding.GetEncoding(0); StreamReader sr = new StreamReader("gb.txt", ansi); string source = sr.ReadToEnd(); sr.Close(); Console.WriteLine(source); using(StreamWriter sw = new StreamWriter("utf.txt",true,Encoding.UTF8)) { sw.Write(source); } Console.ReadLine();