所谓的文件分隔符号是自己定义的。以下给你示范一个:
procedure InitPack; //初始化打包文件 文件名为MyBack.pak
var f:File;
begin
AssignFile(f,'MyBack.pak');
ReWrite(f,1);
CloseFile(f);
end;
procedure PackFile(FileName: string); //对FileName文件打包
var
FromF,ToF:File;
fsize:Longint;
NumRead,NumWrite:Integer;
ss1,ss2,ss3:string[100];
buf:array[1..2048] of char;
begin
AssignFile(ToF,'MyBack.pak'); //打包文件名MyBack.pak
AssignFile(FromF,FileName);
ReSet(ToF,1); //打开打包文件
ReSet(FromF,1); //打开被打包文件
fsize:=FileSize(ToF);
Seek(ToF,fsize);
fsize:=FileSize(FromF); //获取被打包文件长度
Seek(FromF,0);
ss1:='CHANGE'; //打包文件标志
ss2:=FileName;
Str(fsize,ss3); //将文件长度值变为字符串
BlockWrite(ToF,ss1,10); //写出入标志至打包文件中
BlockWrite(ToF,ss2,30); //写入文件名至打包文件中
BlockWrite(ToF,ss3,20); //写入文件长度至打包文件中
repeat //写文件
BlockRead(FromF,Buf,SizeOf(Buf),NumRead);
BlockWrite(ToF,Buf,NumRead,NumWrite);
until (NumRead=0)or(NumWrite<>NumRead);
CloseFile(ToF);
CloseFile(FromF);
end;
procedure DePackFile(FileName:string); //对文件解包
var
FromF,ToF:File;
ss1,ss2,ss3:string[40];
fsize:longint;
NumRead,NumWrite,nn:Integer;
buf:array[1..2048] of char;
begin
AssignFile(FromF,FileName);
ReSet(FromF,1);
while not Eof(FromF) do
begin
BlockRead(FromF,ss1,10,nn); //读取标志
BlockRead(FromF,ss2,30,nn); //读取文件名称
BlockRead(FromF,ss3,20,nn); //读取文件长度
if nn<20 then //如果文件长度不对
begin
ShowDlg('文件尺寸不对');
CloseFile(FromF);
Exit;
end;
fsize:=StrToInt(ss3);
if ss1<>'CHANGE' then //检查标志是否正确
begin
ShowDlg('标志不对');
CloseFile(FromF);
Exit;
end;
AssignFile(ToF,ss2);
ReWrite(ToF,1);
repeat //解开一个文件
if fsize>2000 then
begin
nn:=2000;
fsize:=fsize-2000;
end else
begin
nn:=fsize;
fsize:=0;
end;
BlockRead(FromF,Buf,nn,NumRead);
BlockWrite(ToF,Buf,NumRead,NumWrite);
until (fsize=0)or(NumWrite<>NumRead);
CloseFile(ToF);
end;
CloseFile(FromF);
end;
以上代码好好看看。我做了一个控件,挺好用的。以上代码是我控件
其中的一部分,但足够解决你的问题了