I was using the following to write to a file:
using(Stream FileStream = File.OpenWrite(FileName))
FileStream.Write(Contents, 0, Contents.Length);
I noticed that it was simply writing to file file correctly, but didn't wipe the contents of the file first. I then decided to simply use:
File.WriteAllBytes(FileName, Contents);
This worked fine.
However, why doesn't File.OpenWrite automatically delete the contents of the file as the other languages i've used do for their OpenWrite style function, and have a instead of appending?
Is there any method to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…