想到了保存的代码,想不出读回数组的代码。下次运行程序可怎么办
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
是包含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();