1/29
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
File
A static class in System.IO that provides methods for creating, copying, moving, deleting, opening, reading, and writing files. Domain: C# → .NET → System.IO → Files
File.Exists(path)
Determines whether a file exists at the specified path and returns false rather than throwing for many invalid or inaccessible path situations.
File.Create(path)
Creates or overwrites a file at the specified path and returns a FileStream for accessing it.
File.Delete(path)
Deletes the specified file; if the file does not exist, the method does not throw merely because it is absent.
File.Copy(source, destination)
Copies an existing file to a new location and does not overwrite an existing destination file by default.
File.Copy(source, destination, overwrite)
Copies a file while allowing the caller to specify whether an existing destination file may be overwritten.
File.Move(source, destination)
Moves a file from one path to another.
File.Replace(source, destination, backup)
Replaces the contents of one file with another file and can create a backup of the replaced file.
File.ReadAllText(path)
Opens a text file, reads all of its text into a string, and closes the file.
File.ReadAllText(path, encoding)
Reads all text from a file using the specified character encoding.
File.ReadAllLines(path)
Reads all lines of a text file into a string array, with one array element per line.
File.ReadLines(path)
Returns an enumerable sequence of lines that are read lazily rather than loading all lines into an array at once.
File.ReadAllBytes(path)
Reads the entire contents of a file into a byte array.
File.WriteAllText(path, contents)
Creates or overwrites a file and writes the specified text to it.
File.WriteAllText(path, contents, encoding)
Creates or overwrites a file and writes text using the specified character encoding.
File.WriteAllLines(path, contents)
Creates or overwrites a file and writes a sequence of text lines to it.
File.WriteAllBytes(path, bytes)
Creates or overwrites a file and writes the specified byte array to it.
File.AppendAllText(path, contents)
Opens or creates a file and appends text to its end without replacing the existing contents.
File.AppendAllLines(path, contents)
Appends a sequence of lines to a file, creating the file if necessary.
File.OpenRead(path)
Opens an existing file for reading and returns a FileStream.
File.OpenWrite(path)
Opens an existing file or creates a new file for writing and returns a FileStream.
File.Open(path, mode)
Opens a file using the specified FileMode and returns a FileStream.
File.Open(path, mode, access, share)
Opens a file while explicitly controlling creation/opening behavior, permitted access, and sharing behavior.
File.GetCreationTime(path)
Gets the creation date and time of the specified file.
File.GetLastWriteTime(path)
Gets the date and time when the specified file was last written to.
File.GetLastAccessTime(path)
Gets the date and time when the specified file was last accessed.
File.SetLastWriteTime(path, time)
Sets the last-write date and time of the specified file.
File.Encrypt(path)
Encrypts a file using operating-system file encryption where the API and underlying platform support it.
File.Decrypt(path)
Decrypts a file previously encrypted through supported operating-system file encryption.
File vs FileInfo
File provides static operations using file paths directly, whereas FileInfo represents a particular file as an object with instance properties and methods.