C# 操作记事本文本
2017-11-23 16:26
225 查看
protected void PublicAction(string slowStr)//slowStr就是你想写入的文本
{
FileStream fs = new FileStream(@"F:\log.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine("WindowsService: " + slowStr + " " + DateTime.Now.ToString() + "\n\n");//写入文本
sw.Flush();
sw.Close();
fs.Close();
}
public stringPublicActionRead(string path)
{
StreamReader sr = new StreamReader(path, Encoding.Default);
String str;
while ((str= sr.ReadLine()) != null)
{
str+=str;
}
return str;//str就是读取出来的所有文本
}
{
FileStream fs = new FileStream(@"F:\log.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine("WindowsService: " + slowStr + " " + DateTime.Now.ToString() + "\n\n");//写入文本
sw.Flush();
sw.Close();
fs.Close();
}
public stringPublicActionRead(string path)
{
StreamReader sr = new StreamReader(path, Encoding.Default);
String str;
while ((str= sr.ReadLine()) != null)
{
str+=str;
}
return str;//str就是读取出来的所有文本
}
相关文章推荐
- C#模拟操作记事本
- C# 串口操作系列(4) -- 协议篇,文本协议数据解析(转)
- C#字符串操作 取文本左边 取文本右边 取文本中间 取文本中间到List集合 指定文本倒序
- C# IO操作,写入文本到txt文件.
- C#字符串操作 取文本左边 取文本右边 取文本中间 取文本中间到List集合 指定文本倒序
- c#操作txt文本之写入
- C#操作Word之TypeText()写文本
- C#操作Word总结(二)——设置文档格式并添加文本内容、超链接、添加图片
- C# 串口操作系列(4) -- 协议篇,文本协议数据解析
- 黄聪:C#操作Word -- 插入文本
- C#中操作Word(3)—— 利用Range对象读取和设置Word中的文本
- C# 简单文本文件操作 LOG
- C# 串口操作系列(4) -- 协议篇,文本协议数据解析
- C#(winform) 操作.txt文本的例子
- C#操作文本读写流--- StreamWritter and StreamReader
- !!无须定义配置文件中的每个变量的读写操作,以下代码遍历界面中各个c#控件,自动记录其文本,作为配置文件保存
- Java学习笔记——文本操作(记事本实现)
- C# 串口操作系列(4) -- 协议篇,文本协议数据解析
- C# 串口操作系列(4) -- 协议篇,文本协议数据解析
- C#中操作Word(4)—— 利用Range对象设置文本的格式