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

#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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值