我有一个本地化的应用程序,可在欧洲使用。StreamReader抱怨文件不存在,但它确实存在
我有一个从磁盘加载文件的菜单选项。
此操作工作正常我的开发计算机上,但在虚拟机上不工作,我用它来测试其他操作系统_如法国,产生西班牙语等
一个FileNotFoundException异常时的StreamReader尝试打开该文件。
它说: “ '无法找到文件C:\ Program Files文件\ MyCompany的\ MyTool \ BIN \文件\ DEBUG.TXT'”
事情是,该文件确实存在,在正确的位置,并与正确的文件名。
目标(法语)操作系统上的目录名称与开发机器相同。
任何想法?
string ourPath = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
try
{
System.IO.StreamReader sr = System.IO.File.OpenText(ourPath + @"\bin\Files\debug.txt");
string input = null;
while ((input = sr.ReadLine()) != null)
{
m_text.Append(input);
}
sr.Close();
}
catch (System.IO.FileNotFoundException)
{
MessageBox.Show("LoadDebugOptions: File Not Found: " + ex.Message);
}
尝试使用File.Exists方法来验证文件是否存在。 – Faisal 2010-01-27 12:17:34