Create File
using System.IO;
using System;
class CreateFile
{
static void Main()
{
// Creates a new file or truncates the existing file with the file mode 'create'.
FileStream fs1 = new FileStream("D://myFile.txt", FileMode.Create);
Console.WriteLine("myFile created successfully");
fs1.Close();
// Creates a new file.But if it exists, throws an IO exception when using 'createNew' mode.
FileStream fs2 = new FileStream("D://newFile.txt", FileMode.CreateNew);
Console.WriteLine("newFile created successfully");
fs2.Close();
Console.ReadLine();
}
}
Output:
myFile created successfully
newFile created successfully