原来都是用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;

相关文章:

  • 2022-12-23
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案