| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1413 人关注过本帖
标题:请问如何读取配置文件
只看楼主 加入收藏
li_ming
Rank: 1
等 级:新手上路
帖 子:74
专家分:0
注 册:2006-4-1
收藏
 问题点数:0 回复次数:7 
请问如何读取配置文件
请问如何读取INI配置文件,我想把配置文件中的某个参数的值读出来,  
搜索更多相关主题的帖子: 文件 INI 参数 
2006-08-22 20:17
chelcf
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2006-4-20
收藏
得分:0 

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace gather
{
class ReadWriteIni
{
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

//写入INI文件
public void IniWriteValue(string Section, string Key, string Value,string path)
{
WritePrivateProfileString(Section, Key, Value, path);
}

//读取INI文件
public string IniReadValue(string Section, string Key, string path)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, path);
return temp.ToString();
}
}
}


2006-08-22 20:35
li_ming
Rank: 1
等 级:新手上路
帖 子:74
专家分:0
注 册:2006-4-1
收藏
得分:0 
谢谢!!!

2006-08-24 11:17
哭泣的百合
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-7-13
收藏
得分:0 

非常感谢二楼的代码!顶!


我就不信温室里的花到户外就不能绽放,笼中的贵鸟就飞不到自己的开阔天空!我要自己打拼.
2007-08-01 17:18
zhengkl
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-8-14
收藏
得分:0 

非常感谢

2007-08-14 09:39
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
收藏
得分:0 
回复:(chelcf)using System;using System.Collecti...
这个 是 C# 的代码 ?这么和 C 差的这么多呀 .>

~~~~~~~~~~~~~~~好好学习~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2007-08-14 13:15
C_B_Lu
Rank: 1
等 级:新手上路
威 望:1
帖 子:453
专家分:0
注 册:2006-1-10
收藏
得分:0 

好东西呀. 很多东西用API弄起来特方便,就是API太难记...


帮助那些真正需要帮助的人,是对帮助你的人最好的回报!
2007-08-14 16:39
快速回复:请问如何读取配置文件
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011040 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved