ini文件读写
来源:互联网 发布:新片场 网络电影 编辑:程序博客网 时间:2024/05/17 04:48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
//引用以便读写ini文件的API函数
using System.Runtime.InteropServices;
namespace Test
{
class Program
{
//对WritePrivateProfileString()声明
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
//对GetPrivateProfileString()声明
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key,string def, StringBuilder retVal,int size, string filePath);
static void Main(string[] args)
{
//取得当前路径
string pstr = Directory.GetCurrentDirectory(); //Application.StartupPath;
//执行写操作
WritePrivateProfileString("Name","Xing","Mei",pstr+@"/Me.ini");
WritePrivateProfileString("Name", "Ming", "XiaoQiang", pstr + @"/Me.ini");
WritePrivateProfileString("BirthDay", "Year", "1986", pstr + @"/Me.ini");
WritePrivateProfileString("BirthDay", "Month", "04", pstr + @"/Me.ini");
WritePrivateProfileString("BirthDay", "Day", "07", pstr + @"/Me.ini");
//执行读操作
StringBuilder temp=new StringBuilder();
GetPrivateProfileString("Name", "Xing", "姓读取错误", temp, 255, pstr + @"/Me.ini");
Console.WriteLine(temp.ToString());
GetPrivateProfileString("Name", "Ming", "名读取错误", temp, 255, pstr + @"/Me.ini");
Console.WriteLine(temp.ToString());
GetPrivateProfileString("BirthDay","Year","生日年读取错误",temp,255,pstr+@"/Me.ini");
Console.WriteLine(temp.ToString());
GetPrivateProfileString("BirthDay", "Month", "生日月读取错误", temp, 255, pstr + @"/Me.ini");
Console.WriteLine(temp.ToString());
GetPrivateProfileString("BirthDay", "Day", "生日日读取错误", temp, 255, pstr + @"/Me.ini");
Console.WriteLine(temp.ToString());
Console.ReadLine();
}
}
}
- C#读写INI文件
- INI文件的读写
- C#读写INI文件
- C#读写INI文件
- C#读写INI文件
- 读写INI文件
- 如何读写INI 文件
- 读写INI文件
- INI文件读写
- 读写Ini文件
- INI文件的读写
- 读写INI文件
- c#读写ini文件
- C#读写INI文件
- C#-读写INI文件
- VC读写INI文件
- VC读写INI文件
- VB读写ini文件
- SQL Server的日期选项
- 无插件在Eclipse中利用Resin调试和开发WEB应用程序
- Ogre 圆形水面的实现
- java程序员必读书籍(转)
- eclipse下resin的配制
- ini文件读写
- 合并DLL到EXE文件中源码
- java创建临时文件
- Java 多线程与并发编程总结
- Eclipse+resin+mysql 安装及环境配置
- jvm调优总结
- 程序员(迷茫篇)
- word安装Mathtype后启动变慢的解决方法
- 使文件下载的自定义连接支持 FlashGet 的断点续传多线程链接下载! JSP/Servlet 实现!