INI 文件的读写操作
在C#中对INI文件进行读写操作,在此要引入using System.Runtime.InteropServices; 命名空间,具体方法如下:
#region 变量 private static readonly string strFilePath = AppDomain.CurrentDomain.BaseDirectory.ToString() + "App.ini";//INI文件路径 #endregion #region 私有方法 /// <summary>
/// 写入INI文件
/// </summary>
/// <param name="section">节点名称[如[TypeName]]</param>
/// <param name="key">键</param>
/// <param name="val">值</param>
/// <param name="filepath">文件路径</param>
/// <returns></returns>
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filepath); /// <summary>
/// 读取INI文件
/// </summary>
/// <param name="section">节点名称</param>
/// <param name="key">键</param>
/// <param name="def">值</param>
/// <param name="retval">stringbulider对象</param>
/// <param name="size">字节大小</param>
/// <param name="filePath">文件路径</param>
/// <returns></returns>
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retval, int size, string filePath); #endregion #region 公共方法 public static string GetValue(string section, string key)
{
try
{
int size = 2048;
StringBuilder temp = new StringBuilder(size);
GetPrivateProfileString(section, key, "", temp, size, strFilePath);
return temp.ToString();
}
catch(Exception e)
{
throw new Exception(e.Message);
} } public static bool WriteValue( string section, string key, string value)
{
try
{
long length= WritePrivateProfileString(section, key, value, strFilePath);
return length>0;
}
catch(Exception e)
{
throw new Exception(e.Message);
}
} #endregion
INI 文件的读写操作的更多相关文章
- Delphi- ini文件的读写操作
一.读INI文件示例 procedure TForm1.FormCreate(Sender: TObject); Var MyIni :Tinifile; glAppPath :string; beg ...
- C#+Access 员工信息管理--简单的增删改查操作和.ini配置文件的读写操作。
1.本程序的使用的语言是C#,数据库是Access2003.主要是对员工信息进行简单的增删改查操作和对.ini配置文件的读写操作. 2.代码运行效果如下: 功能比较简单.其中在得到查询结果后,在查询结 ...
- QT从入门到入土(三)——文件的读写操作
引言 文件的读写是很多应用程序具有的功能,甚至某些应用程序就是围绕着某一种格式文件的处 理而开发的,所以文件读写是应用程序开发的一个基本功能. Qt 提供了两种读写纯文本文件的基本方法: 用 QFi ...
- Android 对 properties文件的读写操作
-. 放在res中的properties文件的读取,例如对放在assets目录中的setting.properties的读取:PS:之所以这里只是有读取操作,而没有写的操作,是因为我发现不能对res下 ...
- C++学习48 对ASCII文件的读写操作
如果文件的每一个字节中均以ASCII代码形式存放数据,即一个字节存放一个字符,这个文件就是ASCII文件(或称字符文件).程序可以从ASCII文件中读入若干个字符,也可以向它输出一些字符. 对ASCI ...
- android报错及解决2--Sdcard进行文件的读写操作报的异常
报错描述: 对Sdcard进行文件的读写操作的时候,报java.io.FileNotFoundException: /sdcard/testsd.txt (Permission denied),在往S ...
- Qt对ini文件的读写
研究了以下Qt下ini文件的读写,不废话,上干货. 写入ini文件 WriteIni.cpp void WriteIni::writeSettings() { QSettings settings(& ...
- java文件的读写操作
java文件的读写操作主要是对输入流和输出流的操作,由于流的分类很多,所以概念很容易模糊,基于此,对于流的读写操作做一个小结. 1.根据数据的流向来分: 输出流:是用来写数据的,是由程序(内存)--- ...
- python使用装饰器对文件进行读写操作'及遍历文件目录
'''使用装饰器对文件进行读写操作''' # def check_permission(func): # '''演示嵌套函数定义及使用''' # def wrapper(*args,**kwargs) ...
随机推荐
- spirng线程池的配置与使用
1.在xml中配置线程池 <!-- 配置线程池 --> <bean id="taskExecutor" class="org.springframewo ...
- java 深度探险 java 泛型
Java泛型(generics)是JDK 5中引入的一个新特性,允许在定义类和接口的时候使用类型参数(type parameter).声明的类型参数在使用时用具体的类型来替换.泛型最主要的应用是在JD ...
- java 泛型详解
public class Base<T>{ Class classType=T.class; public Base(){ //想在这里 得到T的类对象 赋值给 cla ...
- vs git extensions简单使用方法
一.准备工具 0.下载Git windows版本下载 http://git-scm.com/download 1.下载Git Extensions.地址http://sourceforge.net/p ...
- (转)android平台phonegap框架实现原理
(原文)http://blog.csdn.net/wuruixn/article/details/7405175 android平台phonegap框架实现原理 分类: Android2012-03- ...
- html,if标签使用
$vo.auth_id eq $vo2.auth_pid报错不能用 condition里面访问变量,不能用点的形式,应该用['']的形式访问
- [Java Basics2] Iterable, Socket, Reflection, Proxy, Factory DP
Parent interface of Collection: Iterable Interface A class that implements the Iterable can be used ...
- hadoop删除节点。
hadoop节点摘除操作: 1.确定exclude文件的位置. <property> <name>dfs.hosts.exclude</name> <valu ...
- 解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element
解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element 'beans'.Referenced file conta ...
- TCP发送接口的返回值
原文链接: http://blog.csdn.net/ordeder/article/details/17240221 1. TCP发送接口:send() TCP发送数据的接口有send,write, ...