System.IO.IOException: 'The process cannot access the file '@.txt' because it is being used by another process.'

后端 未结 6 631
野的像风
野的像风 2021-01-11 13:15

I am new to programming and I have a question. If I have two functions, one creates a text file and writes into it, while the other opens the same text file and reads from i

6条回答
  •  南方客
    南方客 (楼主)
    2021-01-11 13:27

    In one of the unit tests, I had to create a temp file and then remove it after, and I was getting the above error.

    None of the answers worked. Solution that worked was:

    var path = $"temp.{extension}";
            using (File.Create(path))
            {
            }
    
    
            File.Delete(path);
    

提交回复
热议问题