用C#读写INI文件中,ini文件的名称,我想取相对路径,怎么取?

Snow780311 Snow780311 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
string path = @"test.ini";
INIFile iniRW = new INIFile(path);
string dir1 = iniRW.INIReadFile("Dir", "Dir1");
string dir2 = iniRW.INIReadFile("Dir", "Dir2");

class INIFile
{
public string Path;

[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);

public INIFile(string strPath)
{
Path = strPath;
}

public string INIReadFile(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.Path);
return temp.ToString();

}

public void INIWriteFile(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.Path);
}
}

这样运行,找不到Test.ini文件,
请帮忙!
...全文
评论 4
收藏 已收藏
分享
返回顶部
Snow780311
C# 111,128 成员 642,537 内容