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