存了一些string 数组,有什么好办法读回来呢

.Net技术 码拜 7年前 (2017-04-16) 790次浏览
想到了保存的代码,想不出读回数组的代码。下次运行程序可怎么办存了一些string 数组,有什么好办法读回来呢

    public static void Main()
    {
        string[] str = { "热菜", "凉菜", "酒类", "饮料", "面食" };
        FileStream fs = new FileStream("c:\a.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.None);
        for (int i = 0; i < str.Length; i++)
        {
            byte[] buf = Encoding.UTF8.GetBytes(str[i]);
            fs.Write(buf, 0, buf.Length);
        }
解决方案

20

引用:
Quote: 引用:

撒意思?变量重名呢?

变成了一个数组,

string sr[]="热菜凉菜酒类饮料面食";

是包含5个元素的数组啊

FileStream fs1 = new FileStream("c:\a.txt", FileMode.Open, FileAccess.Read, FileShare.None);
            using (var stream = new StreamReader(fs1, Encoding.UTF8))
            {
                while (!stream.EndOfStream)
                {
                    resultStr.Add(stream.ReadLine());
                }
            }
            var resultArr = resultStr.ToArray();

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明存了一些string 数组,有什么好办法读回来呢
喜欢 (0)
[1034331897@qq.com]
分享 (0)