using System.Text;
using System.IO;
namespace EncodingReader
{
class Program
{
static void Main(string[] args)
{
try {
if (args.Length == 0)
{
Console.Write("请输入完整的命令格式,例如 EncodingReader.exe test.txt");
}
else {
String strFullName = String.Empty;
for (int i = 0; i < args.Length; i++) {
strFullName += args[i];
}
if (!File.Exists(strFullName)) {
Console.WriteLine("文件"+strFullName +"不存在");
}
else {
FileInfo fi = new FileInfo(strFullName);
string strPath = strFullName.Substring(0, strFullName.Length - fi.Name.Length);
string strFileName = fi.Name;
string[] enumEncoding = new string[] {"big5","x-mac-chinesetrad","x-Chinese-CNS",
"x-cp20001","x-Chinese-Eten","x-cp20003","x-cp20004","x-cp20005",
"utf-8", "utf-7", "utf-16", "UnicodeFFFE", "utf-32", "utf-32BE",
"gb2312","GB18030", "hz-gb-2312", "EUC-CN", "x-cp50227", "x-mac-chinesesimp" };
for(int i=0;i<enumEncoding.Length ;i++){
StreamReader sr = new StreamReader(strFullName,Encoding.GetEncoding(enumEncoding[i]));
StreamWriter sw = new StreamWriter(strPath + enumEncoding[i] + "." + strFileName,
false, Encoding.Unicode);
sw.Write(sr.ReadToEnd());
sw.Flush();
sw.Close();
sr.Close();
}
}
}
}
catch (Exception excep)
{
Console.WriteLine(excep.ToString());
}
finally {
Console.WriteLine("请按任一键退出");
Console.Read();
}
}
}
}