给你一个类,可以直接读取INI文件中东西
public class IniFile
{
///
/// ini文件名称(带路径)
///
public string filePath;
//声明读写INI文件的API函数
[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 IniFile(string INIPath)
{
filePath = INIPath;
}
///
/// 写INI文件
///
/// Section
/// Key
/// value
public void WriteInivalue(string Section, string Key, string value)
{
WritePrivateProfileString(Section, Key, value, this.filePath);
}
///
/// 读取INI文件指定部分
///
/// Section
/// Key
///
public string ReadInivalue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.filePath);
return temp.ToString();
}
}
这个文件是文本格式的,用读取文本文件流的方式就可以读出来.