我有一個本地化的應用程序,可在歐洲使用。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