`
eueuy
  • 浏览: 71194 次
  • 性别: Icon_minigender_1
  • 来自: 天津
最近访客 更多访客>>
社区版块
存档分类
最新评论

读写文本文件

阅读更多
//////////////读文本////////////
function ReadText(filename:string):string;
var
S: String;
AllText: String;
F: TextFile;
begin
AssignFile(F, filename); // 将C:\MyFile.txt文件与F变量建立连接,后面可以使用F变量对文件进行操作。
Reset(F); // 打开文件
while not EOF(F) do begin // 使用While循环,一直判断是否到了文件未尾
Readln(F, S); // 读取一行文本
AllText := AllText + S;
end;
CloseFile(F); // 关闭文件
result:=alltext;
end;
 
////////////////写////////////////////
function WriteText(filename,s:string):boolean;
var
F: TextFile;
begin
result:=false;
AssignFile(F, filename); // 将文件与F变量建立连接
append(F); // 打开文件
writeln(F, S); // 写一行文本
CloseFile(F); // 关闭文件
result:=true;
end;
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics