.ini文件 初始化文件
- windows配置文件,由【节,键值对】组成 【节】需要由[]包裹,节后可以跟多个键值对,表示这些键值对属于这个节,多个节相互独立。
- 注释由[;]分号起始,到行尾结束。

[DllImport("kernel32")]
public static extern bool WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
public static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);
public static string ReadIniString(string filePath, string Section, string Ident, string Default)
{
Byte[] Buffer = new Byte[65535];
int bufLen = GetPrivateProfileString(Section, Ident, Default, Buffer, Buffer.GetUpperBound(0), filePath);
string s = Encoding.UTF8.GetString(Buffer, 0, bufLen);
return s.Trim();
}
public static bool WriteIniString(string filePath, string Section, string Ident, string Value)
{
bool bResult = WritePrivateProfileString(Section, Ident, Value, filePath);
return bResult;
}