IO预约

View Code
namespace IODemo
{
class Program
{
static void Main(string[] args)
{
String path = "C:\\YuYue.txt";
StreamWriter sw = null;
try
{
Console.WriteLine("1.Add Appointments\n2.View Appointments\n3.Search\n4.Exit");
Console.Write("Enter Choice:");
int i = int.Parse(Console.ReadLine());
switch (i)
{
case 1:
FileInfo fi = new FileInfo(path);
sw = fi.AppendText();
Console.Write("请输入约定日期(YYYY-MM-DD):");
String date = Console.ReadLine();
sw.Write(date + " " + "\t");
Console.Write("预约人:");
String peo = Console.ReadLine();
sw.Write(peo + " " + "\t");
Console.Write("请输入约定时间:");
String time = Console.ReadLine();
sw.Write(time + " " + "\t");
sw.WriteLine();
Console.WriteLine("数据写入成功!");
sw.Close();
break;
case 2:
using (StreamReader sr = new StreamReader(path))
{
String text = sr.ReadToEnd();
Console.WriteLine("显示所添加的预约信息:");
Console.WriteLine("预约时间\t预约人\t预约信息");
Console.WriteLine(text);
}

break;
case 3:
using (StreamReader sr = new StreamReader(path))
{
Console.Write("请输入要查看约定信息的日期(YYYY-MM-DD):");
date = Console.ReadLine();
String str;//读取一行
while ((str = sr.ReadLine()) != null)
{
String[] arr = str.Split(' ');
if (date == arr[0])
{
Console.WriteLine(arr[0] + arr[1] + arr[2]);
}
}
}
break;
case 4:
Console.WriteLine();
return;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
}
}
}
posted @ 2012-02-29 08:35  翼灵绝  阅读(116)  评论(0编辑  收藏  举报