使用StreamReader逐行读取文件

   ArrayList arrList = new ArrayList();
    void ReadTxt(string url)
    {

        // 使用流读取
        StreamReader sr;
        try
        {
            sr = File.OpenText(url.TrimEnd('\0'));
        }
        catch (Exception e)
        {
            // 通过名称与路径均未找到问价返回空
            Debug.Log(e.Message);
            yield break;
        }
        string line;
        arrList.Clear();
        while ((line = sr.ReadLine()) != null)
        {
            // 逐行读取
            arrList.Add(line);
            Debug.Log(line);
            yield return new WaitForEndOfFrame();
        }

        // 关闭流
        sr.Close();
        // 销毁流
        sr.Dispose();
        // 返回数据链表容器
        //Debug.Log(arrList[1]);
    }

猜你喜欢

转载自blog.csdn.net/u011175163/article/details/129043152
今日推荐