Copy, Create and Update a file, keeping the original file in C#

前端 未结 1 1826
自闭症患者
自闭症患者 2021-01-23 12:16

I am trying to copy my file (fileName) into a folder call backup. When the file have been successfully copied into the backup folder, the modifySQLFile() will than read the file

相关标签:
1条回答
  • 2021-01-23 12:51

    First to answer your problem. You are writing to the wrong file in the modifySQLFile() method. Should be destFileName instead of fileName

    File.WriteAllLines(fileName, fileTexts);
    

    Secondly, Assuming this file is not huge (<10MB), the better and easier way will be to read the contents of your original file into memory, modify the contents and then write it into backup. There is no need for CopyFile()

    0 讨论(0)
提交回复
热议问题