当前位置: 编程技术>.net/c#/asp.net
C#清空添加的txt文件的实例代码
来源: 互联网 发布时间:2014-08-30
本文导语: C#操作txt文件,进行清空添加操作的例子。 代码: 代码示例: //把txt清空 FileStream stream = File.Open(Adr,FileMode.OpenOrCreate,FileAccess.Write); stream.Seek(0, SeekOrigin.Begin); stream.SetLength(0); stream.Close(); //向txt里面追加信息 StreamWriter sw = ne...
C#操作txt文件,进行清空添加操作的例子。
代码:
代码示例:
//把txt清空
FileStream stream = File.Open(Adr,FileMode.OpenOrCreate,FileAccess.Write);
stream.Seek(0, SeekOrigin.Begin);
stream.SetLength(0);
stream.Close();
//向txt里面追加信息
StreamWriter sw = new StreamWriter(Adr,true,Encoding.GetEncoding("gb2312"));
sw.WriteLine(str);
sw.Flush();
sw.Close();
FileStream stream = File.Open(Adr,FileMode.OpenOrCreate,FileAccess.Write);
stream.Seek(0, SeekOrigin.Begin);
stream.SetLength(0);
stream.Close();
//向txt里面追加信息
StreamWriter sw = new StreamWriter(Adr,true,Encoding.GetEncoding("gb2312"));
sw.WriteLine(str);
sw.Flush();
sw.Close();