博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

把TXT GB2312文件转换成TXT UTF8文件

Posted on 2010-08-05 12:24  moss_tan_jun  阅读(2899)  评论(0编辑  收藏  举报

 

 

     

 /// <summary>
        /// 把TXT GB2312文件转换成TXT UTF8文件
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="filepath2"></param>
        private void FileGB2312TOFileUTF8(string filepath, string filepath2)
        {
            filepath = Server.MapPath(filepath);
            filepath2 = Server.MapPath(filepath2);

            StreamReader inStream = new StreamReader(filepath, Encoding.GetEncoding(936));//GB2312
            StreamWriter outStream = new StreamWriter(filepath2, false, Encoding.GetEncoding(65001));//UTF8
            char[] chBuffer = new char[1000];
            int iCount;
            while ((iCount = inStream.Read(chBuffer, 0, 1000)) > 0)
            {

                outStream.Write(chBuffer, 0, iCount);
            }
            inStream.Close();
            outStream.Close();
        }