I don't really understand it:
FileMode.Create
creates a new file if it doesn't exists, or overwrites one if it does.
FileMode.Truncate
doesn't create a new file, but deletes the entire content of an existing one, so basically it also overwrites the file.
So why is there even the possibility to do:
public void DoStuff()
{
using (FileStream fs = File.Open(path, FileMode.Truncate, FileAccess.Write, FileShare.None))
{
//Do something
}
}
When it's enough to do:
public void DoStuff()
{
using (FileStream fs = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.None))
{
//Do something
}
}
Because both are basically using an empty file to write stuff into it
Truncate
doesn't create a new file". when do you use it: when you want to overwrite the content of a file, but don't want to create it if it doesn't already exists.