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 ...
- 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文件的编码 ...
- C# 读取ini文件 百度问问学习文档
C# 读取ini文件 10 有多个section,现想读取整个ini文件和指定section下所有内容 补充: 发布答案可以,请对准题目啊,我不要指定节点的内容,我知道!我要的是读取指定区域的内容,假 ...
- python中configparser模块读取ini文件
python中configparser模块读取ini文件 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(se ...
- bat 读取 ini 文件
bat 读取 ini 文件 参考链接:https://stackoverflow.com/questions/2866117/windows-batch-script-to-read-an-ini-f ...
- java读取ini文件
ini工具类; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import j ...
- Python基础之读取ini文件
基本使用方法 第一步:准备一份INI文件.如test1.ini [ITEMS] item1=1 item2=2 item3=3 item4=4 [ITEM1] test1=aaa [ITEM2] te ...
随机推荐
- CoreJava学习笔记1-基本概念、对象和类
一. java的基本程序设计结构 (一) java共有8种基本类型:4种整型,2种浮点类型,1种char,1种boolean. 1) 4种整型:byte(1).short(2). ...
- Java SCP copy local file to remote implementation
最近做的项目中,有一个小需求,需要通过SCP把本地文件copy到远程服务器.查了好多资料,最终解决方案简单快速,分享一下. 在这里,需要用到4个jar包,分别是ant-jsch.jar,ant-lau ...
- centos6虚拟机复制后修改网卡
方法1: 使用vmware创建centos6.4虚拟机, 创建完成后复制该虚拟机, 打开复制的虚拟机发现网卡名字是eth1,而网卡配置文件为eth0,mac地址变了 这时修改网卡配置文件, 删除uui ...
- mysql 报错max_allowed_packet处理办法
首先打开mysql管理工具执行 SHOW VARIABLES LIKE '%max_allowed_packet%'; 看到如图所示的效果 max_allowed_packet 1024slav ...
- HDU 5113 dfs剪枝
题意:告诉格子规格,颜色个数,以及每个颜色能涂得格子数目,问是否能够实现相邻两个格子的颜色数目不相同. 分析:因为数据很小,格子最多是5 * 5大小的,因此可以dfs.TLE了一次之后开始剪枝,31m ...
- AI第一次作业
1. 你认为什么是人工智能? 在我看来,人工智能是是对人的意识.思维的信息过程的高度模拟,虽然它不是人的智能,但是高度模仿人的思考方式,加上它的信息高度集中,对信息的处理速度快,甚至于超过 ...
- Qt for Android开发Android应用时的各种错误汇总(此片博文不成熟,请大家略过)
“Qt for Android真的很脆弱,项目能跑起来靠的是奇迹,跑不起来,各种报错才是正常...” 问题一:Qt for Android编译不过:make (e=2): 系统找不到指定的文件. 之前 ...
- ubuntu eclipse 中安装 python + PyDev
参照网络和个人总结 系统配置:ubuntu12.04 jdk:1.6 eclipse:3.4 首先你的系统必须安装好pyton .也ubuntu系统自带的 刚开始以为是jdk安装 ...
- cocos2dx 之 android java 与 c++ 互相调用 代码(以百度定位为例子)
在作cocosdx项目移植到android上时,预见各种头痛问题,今天首先就说说如何在 java 中调用c++ 代码. 这里就用百度定位为例吧,也是我项目中的一小块内容.首先,先百度一下 “百度定位s ...
- 【转】JavaScript 经常忽略的 7 个基础知识点
原文转自:http://bbs.html5cn.org/thread-83442-1-1.html 1. 在 String.prototype.replace 方法中使用 /g 和 /i标志位 令很多 ...