用文件流,我刚做过一个类似的,只是我读的是SQL语句;
function GetTextFromFile(AFile:string;var ReturnString:string):boolean;
var
Fil:TFileStream;
begin
if not fileexists(AFile) then exit;//判断读取的文件是否存在,不存在中止程序
fil:=TFileStream.Create(AFile,fmOpenRead);//创建文件流
try
if fil.Size>0 then begin
setlength(ReturnString,fil.size);//设置字符串的大小为文件流的数据大小
fil.Read(ReturnString[1],fil.Size);//读取文件流中的数据
result:=true;
end;
finally
fil.Free;//将文件流中的数据是释放掉
end;
end;
这是我定义的一个读取文件流的function,返回的*.txt中的数据就保存在returnstring中,希望对你有帮助