本文整理自网络,侵删。
{函数}
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;
相关阅读 >>
Delphi firedac tfdconnection连接mysql数据库
Delphi下用cdo发送邮箱实例(授权码cdo发送邮箱的解决办法)
Delphi中使用低层钩子 屏蔽win、ctrl+esc、alt+tab、alt+f4
更多相关阅读请进入《Delphi》频道 >>