随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253


问题来源: 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  万一  阅读(...)  评论(...编辑  收藏