没有必要吧?费两遍事?
写一个我的小程序,读的文件虽然没有100m但是10+m还是有的,速度还行。
procedure TForm1.BLClick(Sender: TObject);
var
f:textfile;
s,q:string;
i,j:integer;
begin
s:='C:\Documents and Settings\Administrator\桌面\对比可用额度\';
q:=s;
self.M_A.Lines.Clear;
self.M_B.Lines.Clear;
self.M_A.Lines.BeginUpdate;
self.M_B.Lines.BeginUpdate;
if not fileexists(s+'a.txt') then
showmessage('a.txt不存在!');
if not fileexists(s+'b.txt') then
showmessage('b.txt不存在!');
//读入a.txt,
i:=0;
if fileexists(q+'a.txt') then
begin
assignfile(f,s+'a.txt');
reset(f);
while not eof(f) do
begin
readln(f,s);
//如果是带“.”的需要 s:=stringreplace(s,'.00','',[rfReplaceAll]);
str[i]:=s;
i:=i+1;
//self.M_A.Lines.Add(s);
end;
closefile(f);
end;
// QuickSort(str,0,i-1);
for j:=0 to i-1 do
begin
self.M_A.Lines.Add(str[j]);
end;
//读入b.txt,
if fileexists(q+'b.txt') then
begin
assignfile(f,q+'b.txt');
reset(f);
for i:=1 to 7 do
readln(f,s);
while not eof(f) do
begin
readln(f,s);
// self.M_B.Lines.Add(s);
if (copy(s,1,4)=' ') then
begin
s:=copy(s,16,5)+' '+ floattostr(strtofloat(trim(copy(s,48,15))));
self.M_B.Lines.Add(s);
end;
end;
closefile(f);
end;
self.M_A.Lines.EndUpdate;
self.M_B.Lines.EndUpdate;
还可以用TextFile变量读文本文件,也可以一行一行的读.
var
f: TextFile;
s: string;
begin
AssignFile(f, 'c:\temp.txt');
Reset(f);
while not Eof(f) do
begin
Readln(f, s);
ShowMessage(s);
end;
CloseFile(f);
end;