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 ...
随机推荐
- Nginx+Django+Uwsgi+php
在FreeBSD结合Nginx和FastCGI简单配置Django和PHP http://blog.chinaunix.net/uid-11131943-id-3031767.html Nginx+ ...
- dom classList
才发现dom对象就有classList属性,通过它可以判断该dom是否有指定的class名存在. var tar = e.target; var classList = tar.classList; ...
- [LeetCode]题解(python):042-Trapping Rain Water
题目来源 https://leetcode.com/problems/trapping-rain-water/ Given n non-negative integers representing a ...
- LightOj1190 - Sleepwalking(判断点与多边形的位置关系--射线法模板)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1190 题意:给你一个多边形含有n个点:然后又m个查询,每次判断点(x, y)是否在多边 ...
- JS之setAttribute和getAttribute
1.ele.getAttribute(attributeName); 返回元素的指定属性值,如果元素没有该属性,则返回null 2.ele.setAttribute(attributeName,val ...
- Windows-008-VirtualBox 安装 Win7 前沿配置详解
此文主要讲述在 Windows 系统下安装虚拟机 VirtualBox,及用 VirtualBox 安装 Win7 Professional 64bit 操作系统的前沿配置为例,配以图文进行详细的讲解 ...
- Latency
1)在网络,延迟时间(latency),同义词为延迟,是表示从特定点得到一个数据包(packet)所花的时间.在一些情况下(例如,AT&T),延迟时间用发送出包到回到发送端这个运行一周的时间就 ...
- calc 的使用
通常情况下,一个元素节点使用固定定位absolute和固定定位fixed,会遇到一个问题,如果设置100% ,此时你在对他设置padding,border,margin,它就会撑满 具体情况如下图:
- Android 关于ExpandableListView刷新的解决办法
正文 首先是最基础的 ExpandableListView vList = (ExpandableListView) this.findViewById(R.id.list); EListAdapte ...
- jquery对于table的操作
$("#datable tr").eq(0).children("td").eq(0).html() //获得某行某列的值