博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# INI文件操作
阅读量:1823 次
发布时间:2019-04-25

本文共 2120 字,大约阅读时间需要 7 分钟。

INI文件操作

class INIFileHelper    {
public string path; public INIFileHelper(string INIPath) {
if (ExistINIFile(INIPath)) path = INIPath; } [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); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath); /// /// 验证文件是否存在 /// ///
布尔值
public bool ExistINIFile(string strPath) {
return File.Exists(strPath); } /// /// 写INI文件 /// /// /// /// public void IniWriteValue(string Section, string Key, string Value) {
WritePrivateProfileString(Section, Key, Value, this.path); } /// /// 读取INI文件 /// /// /// ///
public string IniReadValue(string Section, string Key) {
StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path); return temp.ToString(); } public byte[] IniReadValues(string section, string key) {
byte[] temp = new byte[255]; int i = GetPrivateProfileString(section, key, "", temp, 255, this.path); return temp; } /// /// 删除ini文件下所有段落 /// public void ClearAllSection() {
IniWriteValue(null, null, null); } /// /// 删除ini文件下personal段落下的所有键 /// /// public void ClearSection(string Section) {
IniWriteValue(Section, null, null); } }

调用

INIFileHelper inifilehelper = new INIFileHelper("./set.ini");

转载地址:http://vhikf.baihongyu.com/

你可能感兴趣的文章
python3 urllib和requests模块
查看>>
Axure常见的几种原型图
查看>>
svn的checkout与export的区别与使用
查看>>
js实现点击复制功能
查看>>
phpquery采集案例
查看>>
jsp内置对象request的常用方法
查看>>
javascript 0和-0
查看>>
iView3.0样式显示问题(Select和DatePicker)
查看>>
Gulp常用的一些插件
查看>>
Docker:基础知识
查看>>
mysql知识总结
查看>>
C#连接ACCESS
查看>>
linux安装VMtools
查看>>
移动硬盘插入win10检测到却不显示盘符解决方法
查看>>
怎么查看本机S/N序列号和BIOS版本
查看>>
ThinkPad X1 Carbon安装win7.
查看>>
EasyOrtho卫星影像处理软件
查看>>
TerraMaster RAID Manager
查看>>
vmware vcenter converter(物理机转换虚拟机)
查看>>
解决Surface 网卡不识别
查看>>