2013-6-28-StreamWriter写入器

来源:互联网 发布:as网络语言什么意思 编辑:程序博客网 时间:2024/06/05 23:04

1.web

 StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "/xmuser_add.txt", true, Encoding.UTF8);
                        sw.WriteLine("1");
                        sw.Close();




StreamWriter即写入器 ,来自System.IO 命名空间,其包含允许读写文件和数据流的类型以及提供基本文件和目录支持的类型。

//1.既然我们要对文件写入内容,就必须知道对哪个文件写入内容,故这里是获取要写的文件路径

string filePath= AppDomain.CurrentDomain.BaseDirectory + "/manage/webindexdesign/file.html";

//2.使用文件路径创建写入器

            using (StreamWriter sw = new StreamWriter(filePath))

            {

//3.使用Write方法向文件写内容(注意:write方法第一次写时会将文件清空,以后再写时就是追加内容了)

                sw.Write("<!DOCTYPE html><html id=\"htmlidflag\" xmlns=\"http://www.w3.org/1999/xhtml\">");
                sw.Write("<head id=\"headflagid\">");
                sw.Write(decodehead);

                sw.Write("</head>");

             }