第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法將字符串轉換為 system.io

無法將字符串轉換為 system.io

C#
Qyouu 2022-12-24 14:57:52
我試圖讓我的文件流讀取用戶選擇的任何文本文件。文件路徑將在他們選擇后出現在文本框中。我想使用這個文件路徑,以便我的 streamreader 知道要讀取什么文件。"流 fileStream = FilePath.Text;" 不管用。public void ValidateButton_Click(object sender, EventArgs e)        {            {                List<string> temp = new List<string>();                string[] finalArray;                Stream fileStream = FilePath.Text;                using (StreamReader reader = new StreamReader(fileStream))                {                    // We read the file then we split it.                    string lines = reader.ReadToEnd();                    string[] splittedArray = lines.Split(',');                    // We will check here if any of the strings is empty (or just whitespace).                    foreach (string currentString in splittedArray)                    {                        if (currentString.Trim() != "")                        {                            // If the string is not empty then we add to our temporary list.                            temp.Add(currentString);                        }                    }                    // We have our splitted strings in temp List.                    // If you need an array instead of List, you can use ToArray().                    finalArray = temp.ToArray(); }}我得到錯誤無法將字符串轉換為 system.io。如何讓流閱讀器從“文件路徑”文本框中讀取所選文件
查看完整描述

2 回答

?
子衿沉夜

TA貢獻1828條經驗 獲得超3個贊

FilePath.Text返回一個字符串,它是驅動器上文件的位置


下面的代碼可以工作


using (StreamReader reader = new StreamReader(FilePath.Text))

{

    // We read the file then we split it.

    string lines = reader.ReadToEnd();

    string[] splittedArray = lines.Split(',');


    // We will check here if any of the strings is empty (or just whitespace).

    foreach (string currentString in splittedArray)

    {

        if (currentString.Trim() != "")

        {

            // If the string is not empty then we add to our temporary list.

            temp.Add(currentString);

        }

    }


    // We have our splitted strings in temp List.

    // If you need an array instead of List, you can use ToArray().

    finalArray = temp.ToArray();

}


查看完整回答
反對 回復 2022-12-24
?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊

使用接受路徑的構造函數的重載StreamReader

using (StreamReader reader = new StreamReader(FilePath.Text))


查看完整回答
反對 回復 2022-12-24
  • 2 回答
  • 0 關注
  • 194 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號