问题来源: http://www.cnblogs.com/del/archive/2009/03/09/1284244.html#1472084

{函数}
function ReadFileToHex(FileName: string): string;
var
  b: Byte;
begin
  Result := '';
  if not FileExists(FileName) then Exit;
  with TMemoryStream.Create do begin
    LoadFromFile(FileName);
    Position := 0;
    while Position < Size do
    begin
      ReadBuffer(b, 1);
      Result := Result + Format('%.2x ', [b]);
    end;
    Trim(Result);
    Free;
  end;
end;

{调用}
procedure TForm1.Button1Click(Sender: TObject);
var
  str: string;
begin
  str := ReadFileToHex('c:\temp\test.txt');
  ShowMessage(str);
end;

posted on 2009-03-09 18:18  万一  阅读(4145)  评论(9编辑  收藏  举报