用c#来进行文件的写入

来源:互联网 发布:淘宝网老北京布鞋 编辑:程序博客网 时间:2024/05/20 01:11

文件的写入有五个步骤:

创建一个c#窗体

添加引用

添加两个文本框:第一个的属性Name为:tb1 用于装路径,第二个的属性name:tb2用于来写文本类容的

using system.Io;

验证路径是否为空:

            string path = tb1.Text.Trim();///获取路径
            string path1 = tb2.Text.Trim();///创建文本类容

1.创建文件流 FileSt
            FileStream fs = new FileStream(path,FileMode.Create);

2.创建写入器 
            StreamWriter sw = new StreamWriter(fs);

3.将录入的内容写入文件中
            sw.Write(path1);

4.sw.colse();关闭读写器

5.fs.close();关闭文件流