INI就是扩展名为"INI"的文件,其实他本身是个文本文件,可以用记事本打工,主要存放的是用户所做的选择或系统的各种参数. INI文件其实并不是普通的文本文件.它有自己的结构.由若干段落(SECTION)组成,在每个带括号的标题下面,是若干个以单个单词开头的关键字(KEYWORD)和一个等号,等号右边就是关键字的值(VALUE).例如: [Section1] KeyWord1 = Value1 KeyWord2 = Value2 ... [Section2] KeyWord3 = Value3 KeyWord4 = Value4 [DllImport( "kernel32" )] private static extern long WritePrivateProfileString ( string section ,string key , string val , string filePath ) ;
参数说明:section:INI文件中的段落;key:INI文件中的关键字;val:INI文件中关键字的数值;filePath:INI文件的完整的路径和名称。 C#申明INI文件的读操作函数GetPrivateProfileString(): [DllImport("kernel32")] private static extern int GetPrivateProfileString ( string section , string key , string def , StringBuilder retVal , int size , string filePath ) ;
参数说明:section:INI文件中的段落名称;key:INI文件中的关键字;def:无法读取时候时候的缺省数值;retVal:读取数值;size:数值的大小;filePath:INI文件的完整路径和名称。 ,this.inipath); return temp.ToString(); } /// <summary> /// 验证文件是否存在 /// </summary> /// <returns>布尔值</returns> public bool ExistINIFile() { return File.Exists(inipath); } }
|
相关文章
- 一个脚本搞定‘toml‘, ‘hocon‘, ‘json‘, ‘yaml‘, ‘ini‘, ‘properties‘配置文件的读写
- C#使用NModbus4读写Modbus数据
- C#读写三菱PLC和西门子PLC数据 使用TCP/IP 协议
- 用java读写ini配置文件
- c# 读写文件时文件正由另一进程使用,因此该进程无法访问该文件
- C#读写三菱PLC和西门子PLC数据 使用TCP/IP 协议 - 烈火123
- C#读写三菱PLC和西门子PLC数据 使用TCP/IP 协议
- C#使用CH341 SPI模块读写SD卡
- [IO] C# INI文件读写类与源码下载 (转载)
- C#读写三菱PLC和西门子PLC数据 使用TCP/IP 协议