C#学习笔记(22)——C#创建⽂本⽂件txt并追加写⼊数据
说明(2017-7-31 16:25:06):
1. 有两种办法,第⼀种是⽤FileStream创建txt,⽤StreamWriter写⼊数据,期间还要加上判断,是否存在这个txt⽂件,如果不存在就创建,存在就追加写⼊。太⿇烦了!
2. 第⼆种是直接File.AppendAllText(string path, string contents);第⼀个参数是txt路径+⽂件名,第⼆个参数是写⼊内容。这个⽅法会⾃⼰判断⽂件是否存在,直接⼀步到位!
using System;
windows10安装密钥using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows;
namespace PPTtoJPG
{
public class MyLog
{
public void ShowLog(string log)
{
高情商聊天术//第⼀种⽅法,太⿇烦了
//StreamWriter sw = null;
//if (!File.Exists(""))
//{
// FileStream fs = new FileStream("", FileMode.Create, FileAccess.Write);
/
/ sw = new StreamWriter(fs);
// sw.WriteLine(log);
////记得要关闭!不然⾥⾯没有字!
// sw.Close();
// fs.Close();
//}
//else
婴儿拉肚子吃什么//{
十一假期// sw = File.AppendText("");
// sw.WriteLine(log);
// sw.Close();
/
dota斧王出装///MessageBox.Show("已经有log⽂件了!");
//}
//第⼆种⽅法,⽐较简单
潇湘书院穿越小说//\r\n要加在前⾯才会换⾏!
File.AppendAllText("", "\r\n"+log);
}
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论