using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace 流
{
class Program
{
static void Main(string[] args)
{
bool tag=true;
do
{
Console.WriteLine("输入文件名:");
string path = Console.ReadLine();
Console.WriteLine("你是要读取文件信息还是要向文件写入信息?1:读取文件信息,2:向文件写入数据");
int a = Convert.ToInt32(Console.ReadLine());
switch (a)
{
case 1:
if (File.Exists(@path))
{
StreamReader read = new StreamReader(@path, true);
string data = read.ReadToEnd();
Console.WriteLine("内容如下");
Console.WriteLine(data);
}
else
{
Console.WriteLine("你要找的文件不存在");
}
break;
case 2:
if (File.Exists(path))
{
Console.WriteLine("输入你要插入的信息");
string code = Console.ReadLine();
try
{
StreamWriter writer = new StreamWriter(path, true);
writer.WriteLine(code);
writer.Close();
Console.WriteLine("写入成功");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
else
{
Console.WriteLine("文件不存在");
Console.ReadLine();
}
break;
default:
Console.WriteLine("你选择的选项不正确,只能是1或2");
Console.ReadLine();
break;
}
Console.WriteLine("要继续操作吗?继续请按'1',退出请按'2'");
if (Convert.ToInt32(Console.ReadLine()) == 1)
{ tag = true; } //继续循环
if (Convert.ToInt32(Console.ReadLine()) == 2)
{ tag = false;} //结束循环
} while (tag);
//是否结束循环
Console.WriteLine("按任意键退出");
Console.ReadLine();
}
}
}