Class File
Class for creating FileStream objects, and some basic file management routines such as Delete, etc.
public static class File
- Inheritance
-
File
- Inherited Members
Methods
Copy(string, string)
Copies an existing file to a new file. Overwriting a file of the same name is not allowed.
public static void Copy(string sourceFileName, string destFileName)
Parameters
sourceFileName
stringThe file to copy.
destFileName
stringThe name of the destination file. This cannot be a directory or an existing file.
Exceptions
- ArgumentException
sourceFileName
ordestFileName
is null or empty.
Copy(string, string, bool)
Copies an existing file to a new file. Overwriting a file of the same name is allowed.
public static void Copy(string sourceFileName, string destFileName, bool overwrite)
Parameters
sourceFileName
stringThe file to copy.
destFileName
stringThe name of the destination file. This cannot be a directory.
overwrite
booltrue if the destination file can be overwritten; otherwise, false.
Exceptions
- ArgumentException
sourceFileName
ordestFileName
is null or empty.
Create(string)
Creates or overwrites a file in the specified path.
public static FileStream Create(string path)
Parameters
path
stringThe path and name of the file to create.
Returns
Delete(string)
Deletes the specified file.
public static void Delete(string path)
Parameters
path
stringThe name of the file to be deleted. Wildcard characters are not supported.
Exceptions
- ArgumentException
path
is null or empty.- IOException
Directory is not found or
path
is read-only or a directory.
Exists(string)
Determines whether the specified file exists.
public static bool Exists(string path)
Parameters
path
stringThe file to check.
Returns
- bool
true
if the file exists; otherwisefalse
.
GetAttributes(string)
Gets the FileAttributes of the file on the path.
public static FileAttributes GetAttributes(string path)
Parameters
path
stringThe path to the file.
Returns
Exceptions
- IOException
path
cannot be not found.
GetLastWriteTime(string)
Returns the date and time the specified file or directory was last written to.
public static DateTime GetLastWriteTime(string path)
Parameters
path
stringThe file or directory for which to obtain write date and time information.
Returns
- DateTime
A DateTime structure set to the last write date and time for the specified file or directory.
Exceptions
- IOException
path
cannot be not found.
Move(string, string)
Moves a specified file to a new location, providing the option to specify a new file name.
public static void Move(string sourceFileName, string destFileName)
Parameters
sourceFileName
stringThe name of the file to move. Must be an absolute path.
destFileName
stringThe new path and name for the file.
Remarks
.NET nanoFramework implementation differs from the full framework as it requires that sourceFileName
be an absolute path. This is a limitation coming from the platform.
Exceptions
- ArgumentException
sourceFileName
ordestFileName
is null or empty.- IOException
sourceFileName
does not exist ordestFileName
exists.
OpenRead(string)
Opens an existing file for reading.
public static FileStream OpenRead(string path)
Parameters
path
stringThe file to be opened for reading.
Returns
- FileStream
A FileStream on the specified path.
OpenText(string)
Opens an existing UTF-8 encoded text file for reading.
public static StreamReader OpenText(string path)
Parameters
path
stringThe file to be opened for reading.
Returns
- StreamReader
A StreamReader on the specified path.
OpenWrite(string)
Opens an existing file or creates a new file for writing.
public static FileStream OpenWrite(string path)
Parameters
path
stringThe file to be opened for writing.
Returns
ReadAllBytes(string)
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
public static byte[] ReadAllBytes(string path)
Parameters
path
stringThe file to open for reading.
Returns
- byte[]
Exceptions
- IOException
The end of the file was unexpectedly reached.
ReadAllText(string)
Opens a text file, reads all the text in the file, and then closes the file.
public static string ReadAllText(string path)
Parameters
path
stringThe file to open for reading.
Returns
SetAttributes(string, FileAttributes)
Sets the specified FileAttributes of the file on the specified path.
public static void SetAttributes(string path, FileAttributes fileAttributes)
Parameters
path
stringThe path to the file.
fileAttributes
FileAttributesA bitwise combination of the enumeration values.
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.
public static void WriteAllBytes(string path, byte[] bytes)
Parameters
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.
public static void WriteAllText(string path, string contents)