//稍稍修改一下就可以了var F1, F2: File; NumRead, NumWritten: Integer; Buf: array[0..19] of Char; begin AssignFile(F1, 'test1.bin'); Reset(F1, 1); // Record size set to 1 AssignFile(F2, 'test2.bin'); Rewrite(F2, 1); // d.o. repeat BlockRead(F1, Buf, SizeOf(Buf), NumRead); BlockWrite(F2, Buf, NumRead, NumWritten); until (NumRead = 0) or (NumWritten <> NumRead); CloseFile(F2); CloseFile(F1);end;
var UnTypedFile: File; Buffer: array[0..20] of byte; NumRecsRead: Integer; begin AssignFile(UnTypedFile, ‘SOMEFILE.DAT’); Reset(UnTypedFile); try BlockRead(UnTypedFile, Buffer, 1, NumRecsRead);//读20字节 ..........//和上面类似 finally CloseFile(UnTypedFile); end; end;
var fs:TFileStream; buf:array[0..100] of char; begin if fileexists(extractfilepath(application.ExeName)+'TopicView.txt') then begin try fs:=TFileStream.Create(extractfilepath(application.ExeName)+'TopicView.txt',fmOpenRead); fs.Position:=0; if fs.Size>20 then begin fs.Read(buf,20); edit1.Text:=buf; end; if fs.size>fs.Position +30 then begin fs.Read(buf,20); edit2.Text:=buf; end; finally fs.Free; end; end;end;
F1, F2: File;
NumRead, NumWritten: Integer;
Buf: array[0..19] of Char;
begin
AssignFile(F1, 'test1.bin');
Reset(F1, 1); // Record size set to 1
AssignFile(F2, 'test2.bin');
Rewrite(F2, 1); // d.o. repeat
BlockRead(F1, Buf, SizeOf(Buf), NumRead);
BlockWrite(F2, Buf, NumRead, NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead); CloseFile(F2);
CloseFile(F1);end;
UnTypedFile: File;
Buffer: array[0..20] of byte;
NumRecsRead: Integer;
begin
AssignFile(UnTypedFile, ‘SOMEFILE.DAT’);
Reset(UnTypedFile);
try
BlockRead(UnTypedFile, Buffer, 1, NumRecsRead);//读20字节
..........//和上面类似
finally
CloseFile(UnTypedFile);
end;
end;
fs:TFileStream;
buf:array[0..100] of char;
begin
if fileexists(extractfilepath(application.ExeName)+'TopicView.txt') then
begin
try
fs:=TFileStream.Create(extractfilepath(application.ExeName)+'TopicView.txt',fmOpenRead);
fs.Position:=0;
if fs.Size>20 then
begin
fs.Read(buf,20);
edit1.Text:=buf;
end;
if fs.size>fs.Position +30 then
begin
fs.Read(buf,20);
edit2.Text:=buf;
end;
finally
fs.Free;
end;
end;end;