In. all input and output in the. NET Framework must use a stream. A stream is an abstract serialized device that stores data in a linear manner and can be accessed in the same way: one byte is accessed at a time.
This device can be a disk file, printer, memory location, and any other object that supports linear read/write.
When writing data to some external targets, you need to use the output stream, which can be physical disk files, network locations, printers, or other programs.
Common classes:
File ---- static class, which provides many static methods for moving, deleting, and copying files.
Dictionary ---- category class, which provides many static methods for moving, deleting, and copying directories.
Path ---- use a class to process the path name.
Fileinfo ---- indicates the logistics file on the disk. You can use this method to process the file. to read and write the file, you must create a stream object.
Dictionaryinfo ---- indicates the physical directory on the disk, which can be processed.
Filestream ----- indicates a file that can be written, read, or written asynchronously.
Streamreader ------ reads character data from the stream and can be created as the base class by using filestream.
Streamwriter ------ write character data to a stream. You can use filestream to create a base class.
Filesystemwatcher ----- monitors files and directories and provides events that can be captured by applications when these locations change.
?
- File and dictionary classes
As a classification class, the file and dictionary classes provide many methods for processing file systems and files and directories. These are static methods that involve moving files, querying and updating attributes, and creating filestream objects.
File:
Copy () ----- copy the file to the specified location
Create () ----- create a file at a specified location
Delete () ---- delete an object
Open () ----- return the filestream object in the specified path
Move () ---- move the specified file to a new location. You can specify different names for the file in the new location.
Common static methods of directory classes
Createdirectory () ----- create a directory with a specified path
Delete () ----- delete a specified directory and all files in it
Getdirectories () ----- returns the array of directory objects in the directory before the current directory
Getfiles () ----- returns the array of file objects in the current directory
Move () ----- move the specified directory to a new location. You can specify a new name for the folder in the new location.
- Fileinfo class
Unlike the file class, the fileinfo class has no static method and can only be used to instantiate objects. The fileinfo object indicates a file in a disk or network location,
C # File Operations