码迷,mamicode.com
首页 > 其他好文 > 详细

写入文件

时间:2016-07-13 00:56:56      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

        public void Write(string words)
        {

            var pathUrl = Server.MapPath("/UpFile/CamInfo");
            if (!Directory.Exists(pathUrl))
            {
                Directory.CreateDirectory(pathUrl);
            }
            var path = pathUrl + "/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
            FileStream fs = new FileStream(path, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);
            //开始写入
            sw.Write(words);
            //清空缓冲区
            sw.Flush();
            //关闭流
            sw.Close();
            fs.Close();
        }

写入文件

标签:

原文地址:http://www.cnblogs.com/change4now/p/5665210.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!