using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO;

namespace 读写ini文件 {     public class 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);

private string sPath = null;         public Ini(string path)         {             this.sPath = path;         }

public void Writue(string section, string key, string value)         {

// section=配置节,key=键名,value=键值,path=路径

WritePrivateProfileString(section, key, value, sPath);

}         public string ReadValue(string section, string key)         {

// 每次从ini中读取多少字节

System.Text.StringBuilder temp = new System.Text.StringBuilder(255);

// section=配置节,key=键名,temp=上面,path=路径

GetPrivateProfileString(section, key, "", temp, 255, sPath);

return temp.ToString();

}

}     class Program     {         static void Main(string[] args)         {             string Current;

Current = Directory.GetCurrentDirectory();//获取当前根目录             Console.WriteLine("Current directory {0}", Current);             // 写入ini             Ini ini=new Ini(Current+"/config.ini");             ini.Writue("Setting","key1","hello word!");             ini.Writue("Setting","key2","hello ini!");             ini.Writue("SettingImg", "Path", "IMG.Path");             // 读取ini             string stemp = ini.ReadValue("Setting","key2");             Console.WriteLine(stemp);

Console.ReadKey();         }            } }

c#读取INI文件的更多相关文章

  1. C#读取ini文件的方法

    最近项目用到ini文件,读取ini文件,方法如下: using System; using System.Collections.Generic; using System.Linq; using S ...

  2. VS VC 读取 INI文件

    1.获取应程序同极目录下的config.ini路劲 void GetConfigFilePath(char *path,int len, char *file) { char module[256] ...

  3. C# 读取ini文件,读不出来原因

    先赋上相关读取ini文件代码 public class INIHelper { public string inipath; [DllImport("kernel32")] pri ...

  4. C# 通过api函数GetPrivateProfileString读取ini文件,取不到值

    通过api函数GetPrivateProfileString读取ini文件,取不到值,测试了好长时间,都不行 确认程序,ini文件都没有错误的情况,最后发现是ini文件编码的原因. 将ini文件的编码 ...

  5. C# 读取ini文件 百度问问学习文档

    C# 读取ini文件 10 有多个section,现想读取整个ini文件和指定section下所有内容 补充: 发布答案可以,请对准题目啊,我不要指定节点的内容,我知道!我要的是读取指定区域的内容,假 ...

  6. python中configparser模块读取ini文件

    python中configparser模块读取ini文件 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(se ...

  7. bat 读取 ini 文件

    bat 读取 ini 文件 参考链接:https://stackoverflow.com/questions/2866117/windows-batch-script-to-read-an-ini-f ...

  8. java读取ini文件

    ini工具类; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import j ...

  9. Python基础之读取ini文件

    基本使用方法 第一步:准备一份INI文件.如test1.ini [ITEMS] item1=1 item2=2 item3=3 item4=4 [ITEM1] test1=aaa [ITEM2] te ...

随机推荐

  1. simple_html_dom配合snoopy使用

    https://github.com/samacs/simple_html_dom Snoopy的特点是“大”和“全”,一个fetch什么都采到了,可以作为采集的第一步.接下来就需要用simple_h ...

  2. c++构造函数 对象初始化

    最近查看了关于c++构造函数的博客,为了防止关键知识的遗忘,特此记录一些要点,以便于今后的查阅. 如果不主动书写构造函数,c++或默认提供一般构造函数,拷贝构造函数以及复制运算符的操作.一般的构造函数 ...

  3. 标准盒子模型和IE盒子模型

    标准盒子模型 = margin + border + padding + content (content =  width | height) IE盒子模型 = margin + content ( ...

  4. jQuery外部框架浅析

    (function(window, undefined) {         var jQuery = ...         ...             window.jQuery = wind ...

  5. LayaAir引擎——(六)

    LayaAir引擎——TiledMap地图图块属性获取和进行墙壁碰撞检测 需要的软件: TiledMap LayaAir IDE 1.0.2版本 所画的地图: pass层: floor层: pass层 ...

  6. destoon二次开发 操作数据库可运行示例

    <?phpdefine('IN_DESTOON', true);$userid= $_REQUEST["userid"];//$basepath=$_SERVER['PHP_ ...

  7. Linux下mysql忘记root密码

    一台机器上的MYSQL服务器很久没用了,忘了root密码无法连接.一时情急,网上搜寻办法,解决,记录在此备用. 修改MySQL的登录设置:  //不同的版本的Linux配置文件的位置也不一样,以Lin ...

  8. iOS 打电话 发短信(转载)

    官方代码 发短息和邮件添加MessageUI.framework 库 发送信息 - (IBAction)showSMSPicker:(id)sender { // You must check tha ...

  9. 使用 RequireJS 优化 Web 应用前端

    基于 AMD(Asynchronous Module Definition)的 JavaScript 设计已经在目前较为流行的前端框架中大行其道,jQuery.Dojo.MooTools.EmbedJ ...

  10. Windows下VTK6.0.0安装详解(CMake使用说明)

    操作系统:Windows7,用到工具:Visual studio.CMake. 1.准备工作 VTK下载: 下载最新VTK稳定版(6.0.0,截至2013年7月)http://www.vtk.org/ ...