字符编码

            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();

 

posted on 2012-06-24 11:02  笑东风  阅读(217)  评论(0编辑  收藏  举报

导航