C#读写记事本(txt)文件

C#写入记事本(txt)文件
方法一: FileStream stream
= new FileStream(@"d:aa.txt",FileMode.Create);//fileMode指定是读取还是写入 StreamWriter writer = new StreamWriter(stream); writer.WriteLine("123456");//写入一行,写完后会自动换行 writer.Write("abc");//写完后不会换行 writer.WriteLine("ABC"); writer.Close();//释放内存 stream.Close();//释放内存 方法二: StreamWriter writer = new StreamWriter("d:\aa.txt"); writer.WriteLine("123456"); writer.Write("abc"); writer.WriteLine("ABC"); writer.Close(); C#读取记事本文件 方法一: FileStream stream = new FileStream(@"d:aa.txt", FileMode.Open); StreamReader reader = new StreamReader(stream); //this.textbox1.Text = reader.ReadLine(); //一次性读取一行 this.textbox1.Text = reader.ReadToEnd(); //一次性读取全部数据 reader.Close(); stream.Close(); 方法二: StreamReader reader = new StreamReader(@"d:\aa.txt"); this.textbox1.Text = reader.ReadToEnd(); reader.Close();

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注