delphi 写文本文件

原来都是用TStringList读取文件内容然后再用它把内容保存进去,今天看到另一个不错的方法


procedure TForm1.Button1Click(Sender: TObject);
var
LogFile: TextFile;
begin
    if not FileExists('c:\Log1.txt') then
    begin
      AssignFile(LogFile, 'c:\Log1.txt');
      Rewrite(LogFile);
      CloseFile(LogFile); //关闭时自动保存文件
    end;
   
    AssignFile(LogFile, 'c:\Log1.txt');
    Append(LogFile);

    writeln(LogFile);
    writeln(LogFile, '*********End**********');
    writeln(LogFile);
    writeln(LogFile, '********begin*********');
    Write(LogFile, 'Begin the same line');
    Write(LogFile, '//the same line');
    CloseFile(LogFile);
end;

posted @ 2009-02-23 11:15  苔苔以苔苔以苔  阅读(1286)  评论(0编辑  收藏  举报
猪先飞