← Interactive API Explorer
Namespace: System.IO

File

Provides static methods for the creation, copying, deletion, moving, and opening of a single file, and aids in the creation of FileStream objects.

Methods (9)

bool Exists(String)
Determines whether the specified file exists.
ParameterDescription
pathThe file to check.
Returns: true if the caller has the required permissions and path contains the name of an existing file; otherwise, false. This method also returns false if path is null, an invalid path, or a zero-length string. If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.
byte[] ReadAllBytes(String)
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
ParameterDescription
pathThe file to open for reading.
Returns: A byte array containing the contents of the file.
String ReadAllText(String)
Opens a text file, reads all the text in the file, and then closes the file.
ParameterDescription
pathThe file to open for reading.
Returns: A string containing all the text in the file.
void WriteAllBytes(String,Byte[])
Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is overwritten.
ParameterDescription
pathThe file to write to.
bytesThe bytes to write to the file.
void WriteAllText(String,String)
Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.
ParameterDescription
pathThe file to write to.
contentsThe string to write to the file.
void Delete(String)
Deletes the specified file.
ParameterDescription
pathThe name of the file to be deleted. Wildcard characters are not supported.
FileStream Open(String,IO.FileMode)
Opens a FileStream on the specified path with read/write access with no sharing.
ParameterDescription
pathThe file to open.
modeA FileMode value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.
Returns: A FileStream opened in the specified mode and path, with read/write access and not shared.
FileStream OpenRead(String)
Opens an existing file for reading.
ParameterDescription
pathThe file to be opened for reading.
Returns: A read-only FileStream on the specified path.
FileStream OpenWrite(String)
Opens an existing file or creates a new file for writing.
ParameterDescription
pathThe file to be opened for writing.
Returns: An unshared FileStream object on the specified path with Write access.