我想使用c#读出一个word文件的16进制表示的数据中,最后一行的16进制值并转换成字符串!我使用FileStream会提示“流不可读取”请问大家有没有什么好的办法。

解决方案 »

  1.   

    16进数 还有行的概念了 byte[] _DocBytes=System.IO.File.ReadAllBytes(@"c:\1.DOC");            string _Text=BitConverter.ToString(_DocBytes);不就全读出来了..然后处理 _DocBytes..或则你当字符串处理_Text就好了..
      

  2.   

    先获取数据,再转化
    public static string UnHex(string hex, string charset)
         {
             if (hex == null)
                throw new ArgumentNullException("");
            hex = hex.Replace(",", "");
            hex = hex.Replace("\n", "");
            hex = hex.Replace("\\", "");
            hex = hex.Replace(" ", "");
            if (hex.Length % 2 != 0)
            {
              hex += "20";
           } 
            byte[] bytes = new byte[hex.Length / 2];         for (int i = 0; i < bytes.Length; i++)
             {
                 try
                {
                    bytes[i] = byte.Parse(hex.Substring(i * 2, 2),
                    System.Globalization.NumberStyles.HexNumber);
                 }
                 catch
                 {
                     throw new ArgumentException("", "");
               }
             }
             System.Text.Encoding chs = System.Text.Encoding.GetEncoding(charset);
             return chs.GetString(bytes);
        }