求助:具体见贴内内容
比如说我把一份通讯录写入到一个文本里面保存,每一行是一组信息,各元素之间用英文","隔开,如:姓名,性别,电话,住址然后我要把它读出来并还原到数组,用StreamReader该怎么实现?
最好有具体代码.
class st
{
private int id;
private string name;
private string filename;
static public st[] inf = new st[100];
public void en()
{
filename = "E:/information.txt";
FileStream file = null;
try
{
file = File.Open(filename, FileMode.Append);
}
catch (Exception)
{
Console.WriteLine("文件打开失败!");
return;
}
StreamWriter write = new StreamWriter(file);
for (int k = 0; k < 100; k++)
{
inf[k] = new st();
}
for (int i = 0; i < 100; i++)
{
Console.Write("学号:");
inf[i].id = int.Parse(Console.ReadLine());
Console.Write("姓名:");
inf[i].name = Console.ReadLine();
write.WriteLine(inf[i].id + "," + inf[i].name);
Console.WriteLine("是否退出信息输入:1、是(请输入“E”);2、否(请输入任意键)");
if (Console.ReadLine() == "E")
break;
else
continue;
}
write.Close();
//就是这里了.
}