c#读取INI文件类
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文件类的更多相关文章
- C#读取ini文件的方法
最近项目用到ini文件,读取ini文件,方法如下: using System; using System.Collections.Generic; using System.Linq; using S ...
- C# 读取Ini配置文件类
配置文件 为fileName.ini 的文件 第一行必须为空,不然读不出值 [section1] key=value key2=value ......... [section2] key=value ...
- C# 读取ini文件 百度问问学习文档
C# 读取ini文件 10 有多个section,现想读取整个ini文件和指定section下所有内容 补充: 发布答案可以,请对准题目啊,我不要指定节点的内容,我知道!我要的是读取指定区域的内容,假 ...
- python中configparser模块读取ini文件
python中configparser模块读取ini文件 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(se ...
- java读取ini文件
ini工具类; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import j ...
- VS VC 读取 INI文件
1.获取应程序同极目录下的config.ini路劲 void GetConfigFilePath(char *path,int len, char *file) { char module[256] ...
- C# 读取ini文件,读不出来原因
先赋上相关读取ini文件代码 public class INIHelper { public string inipath; [DllImport("kernel32")] pri ...
- C# 通过api函数GetPrivateProfileString读取ini文件,取不到值
通过api函数GetPrivateProfileString读取ini文件,取不到值,测试了好长时间,都不行 确认程序,ini文件都没有错误的情况,最后发现是ini文件编码的原因. 将ini文件的编码 ...
- bat 读取 ini 文件
bat 读取 ini 文件 参考链接:https://stackoverflow.com/questions/2866117/windows-batch-script-to-read-an-ini-f ...
随机推荐
- php比较加赋值语句
$a=-2;if ($a < 0 && $a = 1) { echo $a;} 输出1 右面的$a=1可不是条件哦,而是赋值
- onmouseenter与onmouseover
简单的说: mouseenter第一次进入这个元素的某个子元素时触发.一旦触发后,在mouseleave之前,鼠标在这个元素的子元素上触发mouseenter事件,不会触发这个元素的mouseente ...
- CSS之display:block与display:inline-block
1.<span style="display:block; border:red solid 1px; width:100px"></span> 行级元素是 ...
- Intersection of Two Linked Lists | LeetCode
利用两个栈,然后分别存储每一个链表. 继而,相继pop相同的节点. 有些细节需要注意,请看最后的返回值是如何处理的. /** * Definition for singly-linked list. ...
- link标签和script标签跑到body下面,网页顶部有空白
用UltraEdit的16进制编辑模式查看代码,都是EF BB BF开头的,说明都是带BOM的.我手动的将所有文件转成UTF-8 without BOM.页面终于正常了.link,script标签乖乖 ...
- Magento去掉价格的小数点
magento的默认情况,价格后面是有小数点的,我们来看下如何正确的来去掉小数点. 1.复制如下路径的文件 app/code/core/Mage/Directory/Model/Currency.ph ...
- SqlServer2008R2安装步骤
参考http://jimshu.blog.51cto.com/3171847/585023/
- Useful bat command
1.Start and stop the windows services net stop <service name>net start <service name>net ...
- SQLSERVER 数据库查看各表的记录数
select a.name as 表名,max(b.rows) as 记录条数 from sysobjects a ,sysindexes b where a. ...
- linux敲入命令不记录的方法
history 查看命令列表 history 当前shell进程下的记录的 每个伪终端 窗口都是一个单独的进程,会自己记录命 ...