lsj:我不知道你具体的应用需求是什么,我假设:
把一个尺寸为有若干M的文件分解成最大不超过300K的多个文件,代码如下:
const
AFileSize=300*1024;
procedure BreakFile(FileName:string);
function CopyDataToSmallFile(S:TFileStream;Index:integer):integer;
var
T:TFileStream;
begin
Result:=0;
S.Position:=Index*AFileSize;
if S.Position>=S.Size then EXIT;
T:=TFileStream.Create(Format('%s_%d',[FileName,Index]),fmCreate);
try
Result:=T.CopyFrom(S,AFileSize);
finally
T.Free;
end;
end;
var
S:TFileStream;
Index:integer;
begin
S:=TFileStream.Create(FileName,fmOpenRead or fmShareDenyNone);
try
Index:=0;
while CopyDataToSmallFile(Index)=AFileSize do
Inc(Index);
finally
S.Free;
end;
end;