/// <summary>读取文件编码</summary> private void LoadFileEncoding(string fpath) { FileStream fs = new FileStream(fpath, FileMode.Open, FileAccess.Read); becode = be.GetByCode(fs); fs.Close(); }
/// <summary>读取指定字节数组编码</summary> /// <param name="det">获取字节流编码</param> /// <param name="sr">指定字节数组</param> /// <param name="pcoding">返回文本编码文本</param> public static Encoding GetEncoding(ByteEncode det, byte[] sr, ref string pcoding) { pcoding = det.GetByCode(sr); if (pcoding != "") { return(Encoding.GetEncoding(pcoding)); } else { return(Encoding.Default); } }
/// <summary> /// 返回文件的字符编码 /// </summary> /// <param name="paths">文件路径</param> /// <returns>返回文件的字符编码</returns> public static Encoding GetFileEncoding(string paths) { Encoding en = Encoding.Default; try { FileStream fs = new FileStream(paths, FileMode.Open); ByteEncode be = new ByteEncode(); string ens = be.GetByCode(fs); en = Encoding.GetEncoding(ens); fs.Close(); fs = null; } catch { } return(en); }
/// <summary>返回字节数组最接近编码</summary> /// <param name="sr">字节数组</param> /// <returns>返回字节数组最接近编码</returns> public static string GetBytesEncoding(byte[] sr) { ByteEncode be = new ByteEncode(); return(be.GetByCode(sr)); }