C#中把日志导出到txt文本的简单实例
/// <summary>
/// 打日志
/// </summary>
/// <param name="log"></param>
//首先还是要using system.io;
public void write(arraylist log)
{
//将文件保存在桌面,文件名称为当前时间.txt
filestream fs = new
filestream("c:\\users\\ailin\\desktop\\" +
datetime.now.tolongtimestring().replace(":", "") + ".txt", filemode.openorcreate, fileaccess.readwrite);
streamwriter sw = new streamwriter(fs, encoding.default);
foreach( string i in log)
{
sw.write(i.tostring());
}
datetime dt1 = datetime.now;
sw.writeline();
sw.writeline("操作人:cxx");
sw.writeline("日期:"+convert.tostring(dt1));
sw.flush();
sw.close();
}
//string ssaveexcelname =
//"c:\\" + datetime.now.toshortdatestring().replace("-", "") + datetime.now.tolongtimestring().replace(":", "") + ".xls";
public static arraylist achg_slab_len = new arraylist();
private void button2_click(object sender, eventargs e)
{
arraylist cx = new arraylist();
for (int i = 0; i < ss1.activesheet.rowcount; i++)
{
for (int j = 0; j < ss1.activesheet.columncount; j++)
{
cx.add(ss1.activesheet.cells[i, j].text);
cx.add(" ");
}
cx.add("\r\n");
}
//执行导出日志的操作
write(cx);
return;
}
上一篇: c#各种Timer类的区别与用法介绍
下一篇: JavaSwing后台播放音乐mp3
推荐阅读