Advertisement



< Prev
Next >



C# File



The static File class is defined in the System.IO namespace and it provides us static methods to perform the file manipulation operations such as: File class also allows us to get and set the file specific information such as its creation time, last access time, the last time it was written to.




Some commonly used methods of File class


Methods Description
FileStream Create(String path)
This method creates or overwrites a file in the specified path and it returns a FileStream object that provides read/write access to the specified file.

FileStream Open(String path, FileMode mode)
This method opens a FileStream on the specified path with read/write access with no sharing.

The FileMode value specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.

void Move(String sourceFileName, String destFileName)
This method moves a specified file to a new location, providing the option to specify a new file name at the destination.

void Delete(String path)
This method deletes the file specified by the path.

void Copy(String sourceFileName, String destFileName)
This method copies an existing file to a new file. You are not allowed to overwrite a file of the same name.

FileStream OpenRead(String path)
This method opens an existing file for reading and it returns a FileStream object that provides read access to the specified file.

FileStream OpenWrite(String path)
This method opens an existing file or create a new file for writing and it returns an unshared FileStream object that provides read access to the specified file.

bool Exists(String path)
This method determines whether the specified file exists or not.

DateTimeGetCreationTime(String path)
This method returns the creation time of the specified file or directory.

void SetCreationTime(String path, DateTime time)
This method sets the creation time the specified file or directory.

DateTime GetLastAccessTime(String path)
This method returns the last access time of the specified file or directory.

void SetLastAccessTime(String path, DateTime time)
This method sets the last access time of the specified file or directory was written to.

DateTime GetLastWriteTime(String path)
This method returns the last access time of the specified file or directory was written to.

void SetLastWriteTime(String path, DateTime time)
This method sets the last time the specified file or directory was written to.

bool Exists(String path)
This method determines whether a specified file exists or not.

String[] ReadAllLines(String path)
This method opens a text file, reads all lines from it and then closes the file.

String[] ReadAllLines(String path, String[] contents)
This method create a new file, writes a String array to it and closes it.










Please share this article -




< Prev
Next >
< C# BinaryReader
C# Directory >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement