Txt文件编码从Unicode转成ANSI编码。给自己的手机i908的电子书写的程序。

代码没什么。关键就是下面这个方法

 public void test2(string filename,string tofilename )//filename输入原来的文件路径和名称。tofilename转换后文件的位置和名称
        {
            try
            {
                Encoding ecp1252 = Encoding.GetEncoding(936);
                int m = filename.LastIndexOf(@"\");
                string name = filename.Substring(m + 1);
                StreamReader sr = new StreamReader(filename, Encoding.Unicode, false);
                StreamWriter sw = new StreamWriter(tofilename + @"\" + name, false, ecp1252);
                sw.Write(sr.ReadToEnd());
                sw.Close();
                sr.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show("转换过程中出现错误!" + e.ToString());
                this.Close();
                this.Dispose();
            }

        }

本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。

posted @ 2007-07-26 17:34  音乐啤酒  阅读(698)  评论(0编辑  收藏  举报