//通过流的方式添加
StreamWriter writer = new StreamWriter(@"C:\A\ca.txt", true, Encoding.Default);
writer.WriteLine("早上好");
writer.WriteLine("中午好");
writer.Close();
//通过流的当时读取
StreamReader reader = new StreamReader(@"C:\A\ca.txt", Encoding.Default);
Console.WriteLine(reader.ReadToEnd());
while (reader.Peek() > 0)
{
Console.WriteLine(reader.ReadLine());
}
reader.Close();
文件流(FileStream)
//文件流添加
byte[] arr = Encoding.Default.GetBytes("你好");
FileStream fsw = new FileStream(@"C:\A\ca.txt", FileMode.Create);
fsw.Write(arr, 0, arr.Length);
fsw.Close();
//文件流读取
byte[] arr1 = new byte[200];
FileStream fsr = new FileStream(@"C:\A\c.txt", FileMode.Open);
fsr.Read(arr1, 0, 200);
fsr.Close();
Console.WriteLine(Encoding.Default.GetString(arr1));