zoukankan      html  css  js  c++  java
  • 把ANSI格式的TXT文件批量转换成UTF-8文件类型

    把ANSI格式的TXT文件批量转换成UTF-8文件类型

    Posted on 2010-08-05 10:38 moss_tan_jun 阅读(3635) 评论(0编辑 收藏

      

       

    #region 把ANSI格式的TXT文件批量转换成UTF-8文件类型

        class FileControl
        {
            private string path = "";
            private DirectoryInfo dirInfo = null;
            private FileInfo[] fileInfo = null;
            private string msg = "";

            public string Msg
            {
                get { return msg; }
                set { msg = value; }
            }

            public string Path
            {
                get { return path; }
                set { path = value; }
            }

            public FileControl()
            {

            }
            public FileControl(string path)
            {
                this.dirInfo = new DirectoryInfo(path);
            }

            public void getDirInfo(string path)
            {
                this.dirInfo = new DirectoryInfo(path);
            }
            private void getFileInfoArr()
            {
                if (this.dirInfo != null)
                {
                    this.fileInfo = this.dirInfo.GetFiles("*.txt", SearchOption.AllDirectories);
                }
                else
                {
                    this.msg = "无可转换的txt文件";
                }
            }

            public void Transform()
            {

                try
                {
                    this.getFileInfoArr();
                    foreach (FileInfo fi in this.fileInfo)
                    {
                        FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read);
                        StreamReader streamReader = new StreamReader(fs);
                        string newFileName = fi.FullName.Split('.')[fi.FullName.Split('.').Length - 2] + "_.txt";
                        File.WriteAllText(newFileName, streamReader.ReadToEnd(), Encoding.UTF8);
                    }
                    this.msg = "转换完美完成!";
                }
                catch (Exception ex)
                {
                    this.msg = "转换发生异常!异常原因:" + ex.Message;
                }
            }

        }

        #endregion

  • 相关阅读:
    贪心算法 Wooden Sticks
    HDOJ 2189 悼念512汶川大地震遇难同胞——来生一起走
    hdoj1069 Monkey and Banana(最长上升子序列)
    2012级计科《程序设计基础Ⅱ》期末上机考试
    Constructing Roads In JGShining's Kingdom
    c语言学习随笔之指针(二)
    c语言学习随笔之指针(一)
    遍历网页框架结构
    笔记本测试软件(让奸商头疼的软件)0
    ResizePicturevb.net
  • 原文地址:https://www.cnblogs.com/meimao5211/p/3293494.html
Copyright © 2011-2022 走看看