Here are a few of the things that are commonly used:
Create: Typically use this overloaded method,file.create (String) , string is a pathname that represents the full path of the file, and the return value is a FileStream instance;
Copy: Copying an existing file to a new file , there are two overloaded methods,file.copy (String, String) the first parameter is the source file, the second parameter is the destination file, and the file with the same name is not allowed to be overwritten. file.copy (String, String, Boolean) , which allows overwriting of files of the same name, can be set to Boolean. when you perform a copy operation, close the source file first, or you will get an error. At the same time, the second parameter is a new file, which originally does not exist, and if it existed, it would be an error.
Delete: Deletes the specified file. If the specified file does not exist, no exception is thrown.
Open: One of the overloaded methods,File.Open (String, FileMode) opens FileStreamon the specified path in FileMode mode with read/write access. Note that the FileMode here is an enumeration type.
For the above four functions, you can use the following small program to understand:
Using System;
Using System.IO;
Class Test
{
public static void Main ()
{
String path = "Lena.raw";
FileStream fs=file.create (path);//Use creat to create a new file
Fs. Close ();
File.Copy (Path, "Copy_lena.raw");
File.Open ("Copy_lena.raw", FileMode.Open);
File.move ("Lena.raw", @ "D:\new_lena.raw");
File.delete (path);
}
}
The rest can be found in the following list:
To perform this action ... |
See the examples in this topic ... |
Create a text file. |
How to: Write Text to a file |
Writes a text file. |
How to: Write Text to a file |
Reads a text file. |
How to: Read Text from a file |
Appends text to the file. |
How to: Open and append to a log file File.appendtext Fileinfo.appendtext |
Copy the file. |
File.Copy Fileinfo.copyto |
Rename or move the file. |
File.move Fileinfo.moveto |
Delete the file. |
File.delete Fileinfo.delete |
Reads a binary file. |
How to: Read and write to a new data file |
Writes a binary file. |
How to: Read and write to a new data file |
Create a directory. |
CreateDirectory Directory |
Application of File class in C #