Hi!
I want to save XML and firstly if this XML exists I want to delete it.
So I do:
if (File.Exists (path)) {
Debug.Log("DELETING : ");
File.WriteAllText(path,string.Empty);
}
var serializer = new XmlSerializer(typeof(DronesSerialize));
using (var stream = new FileStream(path, FileMode.CreateNew)) {
serializer.Serialize (stream, this);
Debug.Log("WRITING : ");
}
And unfortunetly it doesnt work, my XML just keep getting bigger, it is appending to file instead of deleting and creating new one.
I checked only File.Delete without FileMode.createNew and then it successfully deleted File.
However when it supposed to delete file if exists and then create new file, it appends content to existing one.
Please help, I don’t know what cause this issue.