DELPHI 如何将二进制dump文件转换为txt文本格式
需要此类代码,非常感谢! 展开
procedure TForm1.btn3Click(Sender: TObject);
var
iFileHandle, iFileLength, iBytesRead : Integer;
byteBuff : array of Byte;
i : Integer;
str, stra, strb : string;
begin
iFileHandle := FileOpen('C://myFile1.txt', fmOpenRead);
iFileLength := FileSeek(iFileHandle, 0, 2);
ShowMessage('iFileLength = ' + IntToStr(iFileLength));
FileSeek(iFileHandle, 0, 0);
SetLength(byteBuff, iFileLength);
iBytesRead := FileRead(iFileHandle, byteBuff[0], iFileLength);
FileClose(iFileHandle);
stra := StrPas( PChar(@byteBuff[1]));
ShowMessage('stra=' + stra);
strb := StrPas(@byteBuff[0]);
ShowMessage('strb=' + strb);
SetLength(str, 5);
Move(byteBuff[0], str[1], 5);
ShowMessage('str=' + str);
str := '';
for i:=0 to iBytesRead do
begin
str := str + chr(byteBuff[i]);
end;
ShowMessage(str);
byteBuff := nil;
end;
myFile1.txt 内容:
[true我是中国人]c
对应的二进制内容为:
弹出结果顺序:
注意:
byteBuff
广告 您可能关注的内容 |