This article is a learning note, C # advanced programming 6 chapter 25 file and registry operations
1. Manage File Systems
1. File directory is a static class. You can use these classes to call only one operation of a File or folder.
FIleInfo DirectoryInfo is a sealed class and needs to be instantiated. Therefore, if you operate a file multiple times, you can use these classes.
2. FileInfo can execute Open (), OpenRead (), OpenText (), OpenWrite (), Create (), and CraetText () methods, and they return stream objects.
3. The path class is a static class and cannot be instantiated.
4. file and directory Methods: MoveTo () Delete () CopyTo ()
Ii. Read and Write files
1. List methods:
File. ReadAllText (FilePaht)
File. ReadAll (FillPath, Encoding)
File. ReadAllBytes ()
File. WriteAll (FilePath, content)
File. WriteAll (FilePath, content, Endcoding)
File. WriteAllBytes ()
3. Stream
1. The stream data source can be a file, a network, a pipe, or memory. Among them, System. IO. MemoryStream and System. IO. Sockets. NetwordkStream are used to process the read and write of memory and network respectively.
2. For file read/write, the most common classes are FileSteam, StreamReader, and SteamWriter.
3. If you want to read and write cached streams, you need to write a class that inherits from BufferSteam.
4. To read and write binary files, you must first instantiate FileSteam. either new or FileSteam fs = file. openRead () or file. openWrite () or file. creat () or file. open (). Close () after use ().
5. ReadByte () reads only one byte and converts it to int.
6. SteamReader and SteamWriter are especially suitable for reading and writing text files. The methods of these two classes are ReadLine () and WriteLine ()
7. streamReader reads a file in this form and can then use the sr. readLine () can be read in one row. You can use sr. read () to Read a character or Read all the remaining strings using ReadToEnd.
8. StreamWriter is a file to be written into this form. It is then filled with sw. Write () and closed ().
4. Use DriveInfo () to read drive information ()
V. file security
ACL access control table
6. Read and Write the Registry
1. Registry Introduction: The registry has seven registry nests. You can see five registries using regedit.
HKEY_CLASSES_ROOT (HKCR) contains details about the file types on the system and the file types that can be opened by applications. It also includes registration information for all com components.
HKEY_CURRENT_USER (HKCU) includes the user configuration of the machine currently logged on by the user. Includes desktop settings, environment variables, network and print connections, and other user operation environment settings.
HKEY_LOCAL_MACHINE (HKLM) is a large nest that contains all the software and hardware information installed on the computer. these settings are not unique to users, but can be used to log on to users on the machine. It also contains the HKCR nest. HKCR is not actually an independent nest, but a convenient ing of the registry entry HKLM/SOFTWARE/Classes.
HKEY_USERS (HKUSR) contains the user configurations of all users. It contains the HKCU nest, which is a ing of a key in HKEY_USERS.
HKEY_CURRENT_CONFIG (HKCF) contains hardware information on the machine.
The other two keys contain temporary information, which is often changed.
HKCY_DYN_DATA is a general container that contains illegal data that needs to be stored in the registry.
HKEY_PERFORMANCE_DATA contains information related to the performance of running applications.
2. Registry and RegistryKey.
RegistryKey can be used to complete up to all operations on the registry key, including setting the security level of the key.
Registry can only perform a single access to the Registry key and perform simple operations. Another function is to provide instances with top-level keys.
Registry provides these instances through static attributes. These attributes include ClassesRoot, CurrentConfig, CurrentUser, DynData, LocalMechine, cecedata, and Users.
Forexample: RegistryKey hklm = Registry. LocalMachine;
RegistryKey hkSoftware = hklm. Openkey ("Software ");
To create a key, use CreatSubKey ()
Delete () is required to Delete the key ()
GetValue () and SetValue () are used to obtain and set attributes ()
Close ()
7. Independent storage IsolatedStorageFile
It can be viewed as a virtual hard disk, which can save data items that can only be shared by Applications created or other application instances.
There are two access methods: user and assembly access. It can be accessed by multiple application instances. The other is accessed by users, assemblies, and domains. During such access, each application instance works in its own independent storage.