`class Ini {
// 声明INI文件的写操作函数 WritePrivateProfileString()
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
// 声明INI文件的读操作函数 GetPrivateProfileString()
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, System.Text.StringBuilder retVal, int size, string filePath);
public static bool Write(string section, string key, string value, string sPath) {
// section=配置节,key=键名,value=键值,path=路径
long bOK = WritePrivateProfileString(section, key, value, sPath);
return true;
}
public static string Read(string section, string key, string defaultVal, string sPath) {
// 每次从ini中读取多少字节
System.Text.StringBuilder temp = new System.Text.StringBuilder
C# 读写.ini配置文件
最新推荐文章于 2024-05-29 00:15:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)