文件流操作问题!!!

freehorse_1981 2004-12-19 10:34:56
我的问题大致是这样的:我要把olecontainer中的内容以流的形式存到一个文件中,而且我要多次存入到该文件中,然后我再取出来,大致思路是这样的:在文件头处记录下每次存入时的一个id号,以及起始位置,数据长度,之后再取出来,但是操作总有问题,存入的时候倒是可以,但是取出的时候总是提示说"stream read error".哪位做过这方面的东西,能否给提供一下源码供参考一下。分数不是问题。解决问题一切都好说!
...全文
194 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
victor_yang 2004-12-20
  • 打赏
  • 举报
回复
没试过,顶!
qiujsh 2004-12-19
  • 打赏
  • 举报
回复
以前写过的一段代码,最后100个字节记录了原来文件的长度,然后再取

Procedure TFM_Main.DecomposeFile(path:string); //分解文件
var
f:textfile;
info:FILE_INFO;
i,j:integer;
buf:array[0..4096] of byte;
s:integer;
count,b:integer;
dir,strtmp:string;
FilebottomInfo:array[0..100] of byte;
FileLen:Longint;
begin
//dir:=GetTempDirectory;
strtmp:=' ';
for j:=0 to 100 do
FilebottomInfo[j]:=0;
dir:=path;
try
fstream1:=tfilestream.Create(paramstr(0),fmShareDenyWrite);
filelen:=GetFileSize(application.ExeName);
fstream1.Seek(filelen-100,soFromBeginning);
fstream1.Read(FilebottomInfo,sizeof(filebottominfo));
try
j:=0;
while (j<10)do
begin
if (FilebottomInfo[j]>47) and (FilebottomInfo[j]<121) then
strtmp[j+1]:=chr(FilebottomInfo[j])
else
strtmp[j+1]:=chr(32);
j:=j+1;
end;
filelen:=strtoint(trim(strtmp));
except
exit;
end;
fstream1.Seek(filelen,soFromBeginning);
while fstream1.Position<>fstream1.Size-100 do
begin
fstream1.Read(info,sizeof(info));
count:=0;
assignfile(f,dir+info.filename);
rewrite(f);
closefile(f);
fstream2:=tfilestream.Create(dir+info.filename,fmopenwrite);
fstream2.Size:=0;
i:=info.len div sizeof(buf);
for b:=1 to i do
begin
s:=fstream1.Read(buf,sizeof(buf));
fstream2.Write(buf,s);
inc(count,s);
end;
s:=fstream1.Read(buf,info.len-count);
fstream2.Write(buf,s);
fstream2.Free;
end;
finally
fstream1.Free;
end;
end;
paybfly 2004-12-19
  • 打赏
  • 举报
回复
不太明白,帮顶

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧