码迷,mamicode.com
首页 > Windows程序 > 详细

C# 实现写入文本文件内容功能

时间:2016-11-25 19:42:25      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:system   文本   功能   end   try   write   nbsp   exist   创建   

private void write_txt(string str1, string str2, string str3)
{
System.DateTime currentTime = System.DateTime.Now;
string strYMD = currentTime.ToString("d");
string FILE_NAME = "MyFileSend" + strYMD + ".txt";//每天按照日期建立一个不同的文件名
StreamWriter sr;
if (File.Exists(FILE_NAME)) //如果文件存在,则创建File.AppendText对象
{
sr = File.AppendText(FILE_NAME);
}
else //如果文件不存在,则创建File.CreateText对象
{
sr = File.CreateText(FILE_NAME);
}
sr.WriteLine(str1 + " " + str2 + " " + DateTime.Now.ToString("yyyy-mm-dd hh:mm:ss") +
" " + str3 + "\r\n");//将传入的字符串加上时间写入文本文件一行
sr.Close();
}

 

C# 实现写入文本文件内容功能

标签:system   文本   功能   end   try   write   nbsp   exist   创建   

原文地址:http://www.cnblogs.com/testsec/p/6102600.html

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