C # File Reading (1 ),
1. Steps for reading and writing files:
Create a file stream-create the corresponding reader-Execute read/write operations-close the reader-close the file stream
Create a file stream: FileStream objfs = new FileStream (file path, file opening mode );
File opening mode: FileMode is an enumeration value, which is omitted here
Colleagues who create files can also set permissions.
Create a reader: StreamReader objsr = new StreamReader (objfs, Encoding. UTF8 );
StreamWriter objsw = new StreamWriter (objfs, Encoding. UTF8 );
Enoding is used to solve the garbled problem.
Read/write operations: Read: objsr. ReadToEnd ();
Write: objsw. Write (content );
Close reader: objsr. Close ();
Objsw. Close ();
Close file stream: objfs. Close ();
2. File class
Provides various methods for operating files.
Method |
Description |
Bool Exists (string path) |
Checks whether a specified file exists. This method returns a Boolean value. |
Void Copy (string SourceFileName, String destFileName) |
Copy the content in the source file of the specified path to the target file. If the target file does not exist, create a new file in the specified path. |
Void Move (string SourceFileName, String destFileName) |
Move the specified file to a new path |
Void Delete (string path) |
Delete the specified file,If the specified file does not exist, no exception is thrown. |
3. The Directory class allows you to move or delete folders.
Method |
Description |
Bool Exists (string path) |
Used to check whether a specified folder exists on the disk |
Void Move (string SourceDirName, String destDirName) |
Used to move files or directories and their contents to a new location. |
Void Delete (string path, Bool recursive) |
Delete the specified directory. If boolTrueDelete all contents in the subdirectory. |
Void Delete (string path) |
Delete an empty directory from a specified path |
3. FileInfo class
Because the static methods of the File class are used for security check, if you want to use a File object multiple times, you can use the corresponding instance method of the FileInfo class because security check is not always required.
Attribute/Method |
Description |
Exists |
Checks whether a specified file exists and returns a Boolean value. |
Extension |
Obtain a string that represents the file extension. |
Name |
Get File Name |
FullName |
Obtain the complete directory of a directory or file |
FileInfo CopyTo (string) |
Copying existing files to new files does not allow overwriting of existing files |
Void Delete () |
Permanently delete an object |
Void MoveTo (string) |
Move the specified file to a new location |
4. DirectoryInfo class
If you want to reuse a directory object multiple times, consider using the instance method of the DirectoryInfo class.
Method |
Description |
DirectoryInfo [] GetDirectories () |
Returns the array of subdirectory objects in the current directory. |
FileInfo [] GetFiles () |
Returns the list of files in the current directory (FileInfoObject array) |
Note: file and stream)
A file is an ordered collection of data permanently stored on various media. It is a basic object for data read/write operations.
Stream, in terms of concept, is very similar to a single disk file. It is also the basic object for data reading. The Stream provides us with a continuous byte stream storage space.
File class is a static class mainly used to provide some function libraries.
The static objects class provides many static methods that support basic file operations, including creating, copying, moving, deleting, and opening a file.
C :\
Yes
Refer to this to clean up the C drive:
1. Disable System Restoration: My computer properties/System Restoration/disable System Restoration on all disks, but I will not be able to use system restoration in the future!
2. Disable System sleep: Control Panel/Power Supply/sleep/remove the check before starting system sleep
3. move the virtual memory, my computer properties/advanced/performance/settings/advanced/change/select the C disk, that is, the system disk, select the no-score page, and then set the virtual memory to its disk, A disk with more disk space remaining, such as D, E, and F. set to 1.5 ~ of memory ~ 2.5 times. The size can be set to the same!
5. Clear temporary IE folders, internet Options, and delete temporary and offline files.
6. delete system logs and program logs, my computer/control panel/management tools/Computer Management/Event Viewer/application, right-click/clear events, and clear system logs in sequence
7. Clear system cache: 2000 all files in the system: C: \ WINNT \ system32 \ dllcache
The XP system is: C: \ windows \ system32 \ dllcache all files under the system cache (open my computer/tool/file and Folder Options/hide the protected system file hook off to hide all files on the hook) ). You can also run the sfc.exe/purgecache command to automatically delete the file.
8. Clear the recycle bin
9. delete the files under c: \ windows \ SoftwareDistribution \ Download (the files downloaded when the system is updated are useless if you have installed the updates)
10. Delete all directories under c: \ windows \ RegisteredPackages
11. Delete all Files under C: \ WINDOWS \ Downloaded Program Files
12. view the hidden files that are known to be protected by the system in my computer folder option, and check all the files.
13. Delete c: \ windows \ All files with $8882305 $ (backup files after system update)
Zhidao.baidu.com/question/11035955.html
Zhidao.baidu.com/question/12223613.html
Zhidao.baidu.com/question/14874715.html
... The remaining full text>
C :\
Yes
Refer to this to clean up the C drive:
1. Disable System Restoration: My computer properties/System Restoration/disable System Restoration on all disks, but I will not be able to use system restoration in the future!
2. Disable System sleep: Control Panel/Power Supply/sleep/remove the check before starting system sleep
3. move the virtual memory, my computer properties/advanced/performance/settings/advanced/change/select the C disk, that is, the system disk, select the no-score page, and then set the virtual memory to its disk, A disk with more disk space remaining, such as D, E, and F. set to 1.5 ~ of memory ~ 2.5 times. The size can be set to the same!
5. Clear temporary IE folders, internet Options, and delete temporary and offline files.
6. delete system logs and program logs, my computer/control panel/management tools/Computer Management/Event Viewer/application, right-click/clear events, and clear system logs in sequence
7. Clear system cache: 2000 all files in the system: C: \ WINNT \ system32 \ dllcache
The XP system is: C: \ windows \ system32 \ dllcache all files under the system cache (open my computer/tool/file and Folder Options/hide the protected system file hook off to hide all files on the hook) ). You can also run the sfc.exe/purgecache command to automatically delete the file.
8. Clear the recycle bin
9. delete the files under c: \ windows \ SoftwareDistribution \ Download (the files downloaded when the system is updated are useless if you have installed the updates)
10. Delete all directories under c: \ windows \ RegisteredPackages
11. Delete all Files under C: \ WINDOWS \ Downloaded Program Files
12. view the hidden files that are known to be protected by the system in my computer folder option, and check all the files.
13. Delete c: \ windows \ All files with $8882305 $ (backup files after system update)
Zhidao.baidu.com/question/11035955.html
Zhidao.baidu.com/question/12223613.html
Zhidao.baidu.com/question/14874715.html
... The remaining full text>