FileStream FS=new FileStream (@"H:\Uefx.cd",FileMode .Open );
            
           BinaryReader ReadSr = new BinaryReader(FS);
           byte[] temb =ReadSr .ReadBytes ((int )FS.Length ) ;
           Debug.WriteLine(temb.Length);
           
           FS.Close();
          string tes="";
            foreach (byte byt in temb)
            {
              tes=tes+byt.ToString("x2")+" ";
            }
            textBox3.AppendText(tes);这样太慢啦..谁有好的算法.就像用UE那样一样就开.

解决方案 »

  1.   

    string连加会造成频繁分配内存,另外要将TextBox.WordWrap属性设置为false避免自动换行消耗时间
    参考如下代码
    private string BufToHex(byte[] ABuffer)
    {
        string vCharHexs = "0123456789ABCDEF";
        char[] vChars = new char[ABuffer.Length * 3 + (ABuffer.Length / 16) * 2];
        int j = 0;
        for (int i = 0; i < ABuffer.Length; i++)
        {
            if (i % 16 == 0 && i != 0)
            {
                vChars[j++] = '\r';
                vChars[j++] = '\n';
            }
            vChars[j++] = vCharHexs[ABuffer[i] >> 4];
            vChars[j++] = vCharHexs[ABuffer[i] & 0xF];
            vChars[j++] = ' ';
        }
        return new string(vChars);
    }private void button1_Click(object sender, EventArgs e)
    {
        FileStream FS = new FileStream(@"c:\temp\temp.bin", FileMode.Open);    BinaryReader ReadSr = new BinaryReader(FS);
        byte[] temb = ReadSr.ReadBytes((int)FS.Length);
        FS.Close();
        textBox1.AppendText(BufToHex(temb)); 
    }