关于TFileStream的读写,我想把多个缓冲区中的数据写到一个文件中,但为什么下面的代码不行?(100分)

  • 主题发起人 主题发起人 gdhyj
  • 开始时间 开始时间
G

gdhyj

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);
var
mem:TFileStream;
buf : array [0..1] of byte;
begin
Mem:=TFileStream.Create('c:/abc.txt',fmOpenReadWrite or fmCreate);
buf[0] :=67;
buf[1] :=68;
mem.ReadBuffer(buf,2); //出错
buf[0] :=69;
buf[1] :=70;
mem.ReadBuffer(buf,2);
mem.Free;
mem :=nil;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
mem:TFileStream;
buf : array [0..1] of byte;
begin
Mem:=TFileStream.Create('c:/abc.txt',fmOpenReadWrite or fmCreate);
buf[0] :=67;
buf[1] :=68;
mem.Read(buf,2); //读取
//mem.Position := 0; //指针返回0字节
buf[0] :=69;
buf[1] :=70;
mem.Write(buf,2); //写回去
mem.Free;
mem :=nil;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
mem:TFileStream;
buf : array [0..1] of byte;
begin
Mem:=TFileStream.Create('D:/test.txt',fmOpenReadWrite or fmCreate);
buf[0] :=67;
buf[1] :=68;
mem.Read(buf,2);
buf[0] :=69;
buf[1] :=70;
mem.Write(buf,2);
mem.Free;
mem :=nil;
end;
 
mem.Read(buf,2);
是指从文件中读2个字节到内存?
我的本意是想把b连续二次把buf中的二个字节写到文件中,如何做?
 
用write就OK了,谢谢!
 
呵,楼主的分好象分得不均吧.算,不和你计较了....记得你就行了.
 
后退
顶部