C# The process cannot access the file ''' because it is being used by another process

前端 未结 10 1436
执念已碎
执念已碎 2020-12-18 08:34

The snippet of code was just supposed to write a string into a text file called \"all_results.txt\". I had errors implementing in File.WriteAllText. After searching the net

10条回答
  •  难免孤独
    2020-12-18 08:57

    Pedro:

    As others have stated, opening and closing the file repeatedly might be the issue. One solution not mentioned is to keep the file open for the duration of the processing. Once complete, the file can be closed.

    Or, alternatively, collect your text in a StringBuilder or some other in-memory text storage and then dump the text to the file once the loop finishes.

提交回复
热议问题