→ gd3727:抱歉~已自己找到問題點並解決了。因為「.」字元的關係。 03/07 15:29
※ 編輯: gd3727 來自: 120.96.54.179 (03/07 15:44)
請問為什麼透過listBox1清單取得的檔案路徑會「不合法」...
string FilePath = listBox1.SelectedItem.ToString();
MessageBox.Show(FilePath);//show D:\123.txt
try
{
StreamReader sr = new StreamReader(FilePath, Encoding.Unicode, true);
}
catch (ArgumentException ex)
{
MessageBox.Show(ex.Message);//show 路徑含有不合法的字元
}
若我不從 listBox1 清單取得,直接指派路徑給 StreamReader 就能正常讀取不會有錯誤。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 120.96.54.179
※ 編輯: gd3727 來自: 120.96.54.179 (03/07 11:50)
※ 編輯: gd3727 來自: 120.96.54.179 (03/07 11:51)