Create and/or Write to a file

前端 未结 5 1058
逝去的感伤
逝去的感伤 2021-02-07 01:26

I feel like this should be easy, but google is totally failing me at the moment. I want to open a file, or create it if it doesn\'t exist, and write to it.

The followin

5条回答
  •  醉话见心
    2021-02-07 02:12

    You can use the FileExists function and then use Append if exist or Rewrite if not.

        AssignFile(logFile, 'Test.txt');
    
        if FileExists('test.txt') then
          Append(logFile)
        else
          Rewrite(logFile);
    
       //do your stuff
    
        CloseFile(logFile); 
    

提交回复
热议问题