我有一个十六进制文件abc.aa
用编辑器查看是如下
03 00 00 00 01 07 48 56 37 0c 00 16 22 06 0b 0c
00 04 00 4d 65 6e 75 7c 02 00 00 0a 00 4f 62 6a我想把这些编码存储到aa.txt 文件中
格式如下
0300000001074856370c001622060b0c0004004d656e757c0200000a004f626a我做的"03""04""0A"都会自动变成“3”"4" "a"

解决方案 »

  1.   

    用 FileStream 读取,转换成 byte[],然后修改后写回。
      

  2.   

    using(FileStream fs = new FileStream(" ", FileMode.Open))
    {
        fs.Seek(-1, SeekOrigin.End);
        int b = fs.ReadByte();
    }
      

  3.   

    我用的代码是这样的
         FileStream fs = new FileStream("d:\\abc.aa", FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                StreamWriter sw = new StreamWriter("d:\\aa.txt");
                int length = (int)fs.Length;
                while (length > 0)
                {
                    byte tempByte = br.ReadByte();
                    string tempStr = Convert.ToString(tempByte, 16);
                    sw.WriteLine(tempStr);
                    length--;
                }
                fs.Close();
                br.Close();
                sw.Close();
    但是保存出来的TXT中的的"03""04""0A"都会自动变成“3”"4" "a"
      

  4.   

    sw.WriteLine(tempStr);
    前面加上:
    if (temStr.Length == 1) temStr = "0" + temStr;
      

  5.   

    使用这个方法 "03""04""0A"不会变“3”"4" "a"
    但是现在txt中是这样的
    03
    00
    00
    10
    74
    85
    6a我想要的是
    0300001074856a
      

  6.   

    把sw.WriteLine(tempStr);改成sw.Write(tempStr);试试
      

  7.   

    temStr,应该是 tempStr
    你不能那么机械