把ANSI格式的TXT文件批量转换成UTF-8文件类型
2010-08-05 10:38
603 查看
#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
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
相关文章推荐
- 把ANSI格式的TXT文件批量转换成UTF-8文件类型
- txt文件ANSI和UTF-8存储格式问题---阿西巴
- C++中,将.txt文件的编码由UTF-8转换为ANSI
- 将txt文件批量转换成pdf格式的方法
- 普通dos编码文件批量转换为UTF-8格式文件
- 批量的pdf怎么转换成txt格式的文件
- C++中,将.txt文件的编码由UTF-8转换为ANSI
- 【分享】Android Studio专用文件转换工具:把ANSI文件批量另存为无BOM的UTF-8文件
- Android 读取txt文件并以utf-8格式转换成字符串
- Android 读取txt文件并以utf-8格式转换成字符串
- 要将pdf转换成txt格式的文件怎么转
- Python合并多个UTF-16格式txt文件
- 将windows下的ansi格式文本转换为linux下能识别的UTF-8格式
- ANSI和UTF-8格式文件的区别
- FilesCodingConvert--批量文件编码格式转换工具
- MATLAB的.mat文件与txt文件的相互转换(mat转txt,数据格式设置)
- 识别常见编码格式文件并转换成UTF-8编码的java实现
- lua文件操作(3)----txt文件转换成lua文件的table格式
- Python:将utf-8格式的文件转换成gbk格式的文件
- 批量将Excel2007文件格式xlsx转换为Excel2003文件格式xls的宏原型