File.OpenWrite appends instead of wiping contents?

后端 未结 2 1029
名媛妹妹
名媛妹妹 2020-12-11 14:12

I was using the following to write to a file:

using(Stream FileStream = File.OpenWrite(FileName)) 
   FileStream.Write(Contents, 0, Contents.Length);
         


        
2条回答
  •  温柔的废话
    2020-12-11 14:58

    Yes you are right. File.OpenWrite does not overwrite the file.

    The File.Create is used to overwrite the file if exists.

提交回复
热议问题