软件编程
位置:首页>> 软件编程>> C#编程>> C#操作txt文件,进行清空添加操作的小例子

C#操作txt文件,进行清空添加操作的小例子

  发布时间:2023-05-24 14:06:07 

标签: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();
0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com