其实很简单。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
const BUF_SIZE=1024;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
f:file of byte;
implementation
{$R *.DFM}
function Str2Hex(const data: array of byte): string;
const
Hex:array[0..15] of char='0123456789ABCDEF';
var
i: Integer;
begin
setlength(result,length(data)*2);
for i := 1 to Length(data) do
begin
result[i*2-1]:=Hex[data shr 4];
result[i*2]:=Hex[data and $F];
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
j,NumRead:integer;
b:array[1..BUF_SIZE] of byte;
s: string;
begin
assignfile(f,'a');
Reset(f);
repeat
BlockRead(f,b,BUF_SIZE,NumRead);
s:=Str2Hex(b); //将每个字节以16进制表示
ListBox1.Items.Add(s);
until (NumRead = 0);
closefile(f);
ListBox1.Items.SaveToFile('a.txt');
end;
end.