以文件流的形式写入到文本中

  string str = textBox1.Text;
            string path = @"D:\TEXT.text";
            if (!File.Exists( path ))
            {
                File.Create(path);
            }

            //【1】创建文件流
            FileStream fs = new FileStream(path, FileMode.Append);

            //【2】创建写入器
            StreamWriter sw = new StreamWriter(fs);
            
            //【3】写入文本
            sw.Write(str);

            //【4】关闭写入器
            sw.Close();

            //【5】关闭文件流
            fs.Close();

posted @ 2022-06-17 21:49  libaisheng9723  阅读(129)  评论(0)    收藏  举报