[英]function has stopped working" Error in running the code
我有一個Windows窗體應用程序,該應用程序可以處理我嘗試使其可移植的文本文件數據集(即:要從外部硬盤驅動器或筆式驅動器運行該應用程序,無需將數據集直接復制到C:\\驅動器中。
我變了
StreamReader fileitem = new StreamReader("c:\\dataset.txt");
成
StreamReader fileitem = new StreamReader("dataset.txt");
並將數據集復制到exe文件路徑(.../bin/debug)
但顯示錯誤"function has stopped working"
! 任何想法?
以下是如何獲取可執行文件的絕對路徑的示例:
static public string AssemblyDirectory
{
get
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
從該答案中抽取的樣本
如果實現此屬性,則可以將代碼更新為以下內容:
StreamReader fileitem = new StreamReader(AssemblyDirectory + "dataset.txt");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.