创建ini文件,读文件和写文件
[DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
上面的代码是读文件和写文件,写文件逻辑为判断路径是否存在,如果不存在,创建文件并写入
调用示例
WritePrivateProfileString(section, key, val, Application.StartupPath + @"\setting.ini"); GetPrivateProfileString(section, key, "", temp, 10000, Application.StartupPath + @"\setting.ini");