虽说 XML 文件越发流行,但精简的 ini 配置文件还是经常会用到,在此留个脚印。
当然,文中只是调用系统API,不会报错,如有必要,也可以直接以流形式读取 ini文件并解析。
    /// <summary>
/// 调用系统API 读写 ini 配置文件
/// </summary>
public class RWini
{
#region ========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 void WriteIni(string section, string key, string value,string path)
{
// section=配置节,key=键名,value=键值,path=路径
WritePrivateProfileString(section, key, value, path);
} public static string ReadIni(string section, string key,string path)
{
// 每次从ini中读取多少字节
System.Text.StringBuilder temp = new System.Text.StringBuilder();
// section=配置节,key=键名,temp=上面,path=路径
GetPrivateProfileString(section, key, "", temp, , path);
return temp.ToString();
} #endregion
}

C# 读写 ini 配置文件的更多相关文章

  1. [转]VB 读写ini 配置文件

    转自 百度知道 C# 读写 ini配置文件 点此链接 'API 声明Public Declare Function GetPrivateProfileString Lib "kernel32 ...

  2. 自己写的 读写 ini 配置文件类

    /// <summary> /// 不调用系统API 读写 ini 配置文件 /// </summary> public class RW_ini { #region ==== ...

  3. 引用“kernel32”读写ini配置文件

    引用"kernel32"读写ini配置文件 unity ini kernel32 配置文件  引用"kernel32"读写ini配置文件 OverView ke ...

  4. C# 文件的一些基本操作(转)//用C#读写ini配置文件

    C# 文件的一些基本操作 2009-07-19  来自:博客园  字体大小:[大 中 小] 摘要:介绍C#对文件的一些基本操作,读写等. using System;using System.IO;us ...

  5. C#操作读写INI配置文件

    一个完整的INI文件格式由节(section).键(key).值(value)组成.示例如:[section]key1=value1key2=value2; 备注:value的值不要太长,理论上最多不 ...

  6. c#读写ini配置文件示例

    虽然c#里都是添加app.config 并且访问也很方便 ,有时候还是不习惯用他.那么我们来做个仿C++下的那种ini配置文件读写吧     其他人写的都是调用非托管kernel32.dll.我也用过 ...

  7. WritePrivateProfileString等读写.ini配置文件

    配置文件中经常用到ini文件,在VC中其函数分别为: 写入.ini文件: BOOL WritePrivateProfileString( LPCTSTR lpAppName, // INI文件中的一个 ...

  8. C++读写ini配置文件GetPrivateProfileString()&WritePrivateProfileString()

    转载: 1.https://blog.csdn.net/fengbingchun/article/details/6075716 2. 转自:http://hi.baidu.com/andywangc ...

  9. QT读写ini配置文件

        /********下面是写ini文件*************************/     //Qt中使用QSettings类读写ini文件     //QSettings构造函数的第一 ...

随机推荐

  1. NET Core MVC中创建PDF

    使用Rotativa在ASP.NET Core MVC中创建PDF 在本文中,我们将学习如何使用Rotativa.AspNetCore工具从ASP.NET Core中的视图创建PDF.如果您使用ASP ...

  2. C# 日常

    var lines = JsonConvert.DeserializeObject<List<qqq>>(dataSource); 类参数   publist string d ...

  3. js的以及前端框架

    js定义:浏览器的脚本语言,用简单的语言实现浏览器的操控 基础语法:基础的运算.函数.对象(原型链.对象构造.class) 所有的框架都是基于原生的js来进行的 js的事件:什么时候.什么情况下处理的 ...

  4. hdu4990 Reading comprehension 矩阵快速幂

    Read the program below carefully then answer the question.#pragma comment(linker, "/STACK:10240 ...

  5. 【liunx】date命令总结

    命令简介: date 根据给定格式显示日期或设置系统日期时间.print or set the system date and time 指令所在路径:/bin/date 命令语法: date [OP ...

  6. sqler sql 转rest api 源码解析(三) rest协议

    rest 服务说明 rest 协议主要是将配置文件中的宏暴露为rest 接口,使用了labstack/echo web 框架,同时基于context 模型 进行宏管理对象的共享,同时进行了一些中间件的 ...

  7. Using pointer to access array instead of index

    See example below firstly. uint8_t parity = ; uint8_t index = ; //flag gMUXTask.responseData[index++ ...

  8. Big-endian/Little-endian, LSB/MSB

    Least significant byte (LSB) Most significant byte (MSB) Big-endian machines store the most-signific ...

  9. BeEF介绍

    什么是BeFF?         BeEF是眼下欧美最流行的web框架攻击平台,它的全称是 the Browser exploitation framework project.近期两年国外各种黑客的 ...

  10. 深入理解计算机系统 (Randal E.Bryant / David O'Hallaron 著)

    第1章 计算机系统漫游 (已看) 1.1 信息就是位+上下文 1.2 程序被其他程序翻译成不同的格式 1.3 了解编译系统如何工作是大有益处的 1.4 处理器读并解释存储在内存中的指令 1.4.1 系 ...