1. The. NET Framework provides Files and directories classes. We can create, move and delete files or folders, and these classes and methods are inside System.IO.
2. Method structure diagram in IO
3. Note: The method of the folder is all static, so you cannot create an instance call but use the static method directly
4.
Principal methods of the Directory class (the basic method inside the folder Class) |
Method |
Use |
CreateDirectory () |
Creates all directories and subdirectories specified by its path parameter |
GetCreationTime () |
Returns and sets the time the specified directory was created |
GetDirectories () |
Gets named directories |
GetLogicalDrives () |
Returns the names of all the logical drives in the form <drive>:\ |
GetFiles () |
Returns the names of files matching a pattern |
GetParent () |
Returns The parent directory for the specified path |
Move () |
Moves a directory and its contents to a specified path |
5. The folder information class can get information inside a folder, such as a subdirectory or a file inside a folder
Principal methods and properties of the DirectoryInfo class |
Method or property |
Use |
Delete () |
Public method This deletes a DirectoryInfo and its contents from the path |
GetDirectories () |
Public method This returns a DirectoryInfo array with subdirectories |
GetFiles () |
Public method This returns a list of files in the directory |
Getfilesysteminfos () |
Public method This retrieves an array of FileSystemInfo objects |
MoveTo () |
Public method This moves a DirectoryInfo and its contents to a new path |
Refresh () |
Public method inherited from FileSystemInfo; Refreshes the state of the object |
6. The file class can get the content and content of the file itself.
Principal public static methods of the File class |
Method |
Use |
AppendText () |
Creates a StreamWriter that appends text to the specified file |
Copy () |
Copies an existing file to a new file |
Create () |
Creates a file in the specified path |
CreateText () |
Creates a StreamWriter that writes a new text file to the specified file |
Delete () |
Deletes the specified file |
Exists () |
Returns true if the specified file exists |
GetAttributes (), SetAttributes () |
Gets or sets the fileattributes of the specified file |
7. The file information class can get the record, name and other attributes of the file.
Method or property |
Use |
Attributes () |
Inherits from FileSystemInfo; Gets or sets the attributes of the current file |
CreationTime |
Inherits from FileSystemInfo; Gets or sets the creation time of the current file |
Directory |
Public property This gets an instance of the parent directory |
Exists |
Public property, Boolean value, is true if the directory exists |
Extension |
inherited from FileSystemInfo; That is, the file extension |
FullName |
inherited from FileSystemInfo; That's, the full path of the file or directory |
LastAccessTime |
inherited from FileSystemInfo; Gets or sets the last access time |
LastWriteTime |
Public property Inheritedfrom FileSystemInfo; Gets or sets the time when the current file or directory is last written to |
Length |
Public property which gets the size of the current file |
Name |
Public property Name of this DirectoryInfo instance |
AppendText () |
Public method This creates a StreamWriter that appends text to a file |
CopyTo () |
Public method This copies an existing file to a new file |
Create () |
Public method that creates a new file |
Delete () |
Public method that permanently deletes a file |
MoveTo () |
Public method to move a file to a new location; Can is used to rename a file |
Open () |
Public method This opens a file with various read/write and sharing privileges |
OpenRead () |
Public method that creates a read-only FileStream |
OpenText () |
Public method This creates a StreamReader that reads from an existing text file |
OpenWrite () |
Public method that creates a write-only FileStream |
8. There are many ways to read and write files, such as binary read and write tips: The path is preceded by a few escape characters
9. Buffer buffers are more efficient when large amounts of data are read and written, and calibration is required to ensure correct data
Stream of C #