The Create()
method of the File
class is used to create files in C#. The File.Create()
method takes a fully specified path as a parameter and creates a file at the specified location; if any such file already exists at the given location, it is overwritten.
The syntax for the File.Create()
method is:
The code snippet below illustrates the process of creating a file at a specified path with the File.Create()
method.
using System;using System.IO;using System.Text;class FileCreation{public static void Main(){string path = @"D:\Python_Files\my_file.py";// The line below will create a file my_file.py in// the Python_Files folder in D:\ driveusing (FileStream fs = File.Create(path))}}
The
FileStream
class methods can be called, after the above code is executed, with thefs
object.
Free Resources