Window下的例子:
1。创建文件1:
procedure TForm1.FormCreate(Sender: TObject);
var Stream1:TFileStream;
Buff:Array[1..65536] of char;
Size,Offset,I:Integer;
begin
Offset:=189440;//文件的长度
Stream1:=TFileStream.Create(Application.ExeName,fmShareDenyWrite);//共享读打开
Size := Stream1.Size;
Stream1.Seek(Offset,soFrombegin
ning);
Stream1.Read(Buff,Size-OffSet);//读入到Buff中
Stream1.Free;
Memo1.Text:='';
for i:=1 to (Size-Offset)do
Memo1.Text:=Memo1.Text+Buff;
end;
2。创建文件2,连接文件1与文本。
procedure TForm1.Button1Click(Sender: TObject);
var Stream1:TMemoryStream;
Buff:Array[1..65536] of char;
I,Size:Integer;
begin
Stream1:=TMemoryStream.Create;
Stream1.LoadFromFile('Linkprj1.exe');//读入文件1
Size:=Stream1.Size;
Stream1.SetSize(Stream1.Size+Memo1.GetTextLen);//长度为两者相加。
Stream1.Seek(Size,soFrombegin
ning);
for i:=1 to Memo1.GetTextLendo
Buff:=Memo1.Text;
Stream1.Write(Buff,Memo1.GetTextLen);
Stream1.SaveToFile('link.exe');//写入文件
Stream1.Free;
end;