下面代码是我现在用的,读取的路径是F:\InfoGuard\Gui\bin\Debug\DBConfig.ini,换了盘符也能读取使用,但是每回改配置文件时要进入的文件夹太多,现在我想将DBConfig.ini文件放在F:\InfoGuard\Config\DBConfig.ini,而且换盘符也能自动读取,不知是否可行,请大侠们帮帮忙吧,不胜感激public QueryStatistic()
{
string strAppPath = Application.StartupPath; //获得可执行文件的路径。
string strConfigPath = strAppPath + "\\DBConfig.ini"; FileStream fs = new FileStream(strConfigPath,FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
try
{
strCon = sr.ReadToEnd(); //读取配置文件到strCon变量
}
catch
{
MessageBox.Show("无法读取文件!");
}
finally
{
sr.Close();
fs.Close();
}
}
{
string strAppPath = Application.StartupPath; //获得可执行文件的路径。
string strConfigPath = strAppPath + "\\DBConfig.ini"; FileStream fs = new FileStream(strConfigPath,FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
try
{
strCon = sr.ReadToEnd(); //读取配置文件到strCon变量
}
catch
{
MessageBox.Show("无法读取文件!");
}
finally
{
sr.Close();
fs.Close();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货