//功能:把分割的文件一块一块的读入到文件流中,然后再copy到内存流中,这样就完成了分割文件的合并操作,然后再把内存流保存为硬盘文件,但是,当分割的文件很大时(比如:一块50M,共有10块)时,tmemorystream将会变的很大很大,内存将不能容纳,合并速度会很慢,不知道能不能做出这样的程序:从文件流中读一块,合并工作可以保存为硬盘文件后再进行吗?或者有什么好的方法来合并这样的文件?像rar一样,当rar压缩再多再大的文件时,也不会出现内存使用500M的情况,我想知道这是怎么做的,谢谢!!分不是问题,可以再加!!
var
tfi:tfileinfo;//是一个类,
times:integer;
flag:boolean;
s:string;
begin
s:=getfilename(listbox1.Items[0]);//得到文件名
times:=0;
flag:=true;
form1.ProgressBar1.Max:=listbox1.Count;
if listbox1.Count<>0 then
begin
try
tfi:=tfileinfo.Create;
tfi.filename:=form1.ListBox1.Items[0];
tfi.position:=pos('.',tfi.filename);
tfi.count:=form1.ListBox1.Count; //得到listbox中的itme的条数
try
tfi.ms:=tmemorystream.Create;
for times:=0 to tfi.count-1 do //合并添加到listbox中的文件
begin
tfi.fs:=tfilestream.Create(form1.ListBox1.Items[times],fmopenread);
tfi.ms.CopyFrom(tfi.fs,0);
end;
tfi.ms.SaveToFile(getcurrentdir()+'合并后的'+s+tfi.exname1);//在当前文件夹下保存为文件
tfi.ms.Free;
tfi.Free;
except
tfi.ms.Free;
flag:=false;
messagebox(form1.Handle,pchar('读取文件出错!'),'提示',mb_ok or mb_iconwarning);
end;
if flag then
begin
messagebox(form1.Handle,pchar('文件合并成功!'+#13+'请到目录下:"'+getcurrentdir()+'\"去查看!'),'提示',mb_ok or mb_iconinformation);
form1.ProgressBar1.Visible:=false;
end;
except
tfi.Free;
end;
end
else
begin
messagebox(form1.Handle,pchar('请正确选取您已分割的文件!'),'警告',mb_ok or mb_iconwarning);
end;
end;
//先给40分,解决了另开贴,再加!!
var
tfi:tfileinfo;//是一个类,
times:integer;
flag:boolean;
s:string;
begin
s:=getfilename(listbox1.Items[0]);//得到文件名
times:=0;
flag:=true;
form1.ProgressBar1.Max:=listbox1.Count;
if listbox1.Count<>0 then
begin
try
tfi:=tfileinfo.Create;
tfi.filename:=form1.ListBox1.Items[0];
tfi.position:=pos('.',tfi.filename);
tfi.count:=form1.ListBox1.Count; //得到listbox中的itme的条数
try
tfi.ms:=tmemorystream.Create;
for times:=0 to tfi.count-1 do //合并添加到listbox中的文件
begin
tfi.fs:=tfilestream.Create(form1.ListBox1.Items[times],fmopenread);
tfi.ms.CopyFrom(tfi.fs,0);
end;
tfi.ms.SaveToFile(getcurrentdir()+'合并后的'+s+tfi.exname1);//在当前文件夹下保存为文件
tfi.ms.Free;
tfi.Free;
except
tfi.ms.Free;
flag:=false;
messagebox(form1.Handle,pchar('读取文件出错!'),'提示',mb_ok or mb_iconwarning);
end;
if flag then
begin
messagebox(form1.Handle,pchar('文件合并成功!'+#13+'请到目录下:"'+getcurrentdir()+'\"去查看!'),'提示',mb_ok or mb_iconinformation);
form1.ProgressBar1.Visible:=false;
end;
except
tfi.Free;
end;
end
else
begin
messagebox(form1.Handle,pchar('请正确选取您已分割的文件!'),'警告',mb_ok or mb_iconwarning);
end;
end;
//先给40分,解决了另开贴,再加!!
解决方案 »
- 高手们,问一下问题,请大家说说看--常年在线等
- 我想在电脑屏幕上画矩形框,如何实现。
- 请问各位大侠:有没有关于在delphi中如何使用水晶报表方面的书或者文档呀
- 請教,BDE問題:"Corrupt file-other than header"
- DX们请教一问题
- 如何将网卡设成混杂工作模式?我记得以前在这里见过帖子,搜不到了
- 线程间如何通信?
- 巨简单!Delphi中仅选择目录或文件路径的控件是哪个?
- 怎样用控件NMSMTP发送支持HTML格式的邮件?
- 探讨系列难题(3):进入win98时,提示输入用户,密码窗口,我想用DELPHI编程在出现提示输入用户,密码窗口之前执行,如何实现??
- 如何屏蔽stringgrid中的方向键
- 字符转换
比如:.dat,.rm,.rmvb,.mp3,.wav ……,如何写入这样的文件头?
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
BlockWrite(ToF, Buf, NumRead, NumWritten);這樣, 我想
THeader = packed record
B: Char;
M: Char;
end;var FHeader: THeader;
begin
FHeader.B := 'B';
FHeader.M := 'M'; with TMemoryStream.Create do
try
WriteBuffer(FHeader, SizeOf(THeader));
SaveToFile('C:\Budded.Dat');
finally // wrap up
Free;
end; // try / finally
end;
同时也谢谢各位大侠的参与,谢谢!!