c# 读写文件
2016-07-04 10:57
781 查看
使用c#读写txt文件,记录Log。
参考链接:
http://www.runoob.com/csharp/csharp-file-io.html
http://www.runoob.com/csharp/csharp-text-files.html
http://www.runoob.com/csharp/csharp-binary-files.html
举例
streamwriter对于文件属性的设置方法不是很多,混合FileStream使用。
Author:
Tony Liu
2016-7-4, Shenzhen
参考链接:
http://www.runoob.com/csharp/csharp-file-io.html
http://www.runoob.com/csharp/csharp-text-files.html
http://www.runoob.com/csharp/csharp-binary-files.html
举例
StreamWriter writeLog; writeLog = new StreamWriter("log.txt"); writeLog.WriteLine("hello world"); writeLog.Flush(); //清空缓存,否者文件的内容不会实时更新 writeLog.close(); StreamReader readLog readLog = new StreamReader("log.txt")) string line; line = sr.ReadLine(); Console.WriteLine(line); readLog.close();
streamwriter对于文件属性的设置方法不是很多,混合FileStream使用。
StreamWriter writeLog; StreamWriter writeTempLog; StreamReader readTempLog; FileStream Log; Log = new FileStream("log.txt", FileMode.Create, FileAccess.ReadWrite,FileShare.ReadWrite); writeLog = new StreamWriter(Log); readTempLog = new StreamReader(LogTemp); string logData; logData = readTempLog.ReadLine(); while ((logData = readTempLog.ReadLine()) != null) { writeLog.WriteLine(logData); writeLog.Flush(); } readTempLog.Close(); writeLog.Close(); Log.Close();
Author:
Tony Liu
2016-7-4, Shenzhen
相关文章推荐
- C# 压缩 解压 复制文件夹,文件的操作
- 21 调试我们的C#程序
- 使用跟踪和调试进行条件编译
- C# QRCode 二维码
- C#入门随手笔记
- C#编写数据分析软件(附源码)
- C# 泛型接口
- How to: Create and Initialize Trace Listeners
- C#打印DataGridView数据
- C#高级功能(四)扩展方法和索引
- C#高级功能(三)Action、Func,Tuple
- When to Use Static Classes in C#
- 【C#】Excel导出合并行和列并动态加载行与列
- 追踪监听(TraceListener)
- 使用跟踪和调试进行条件编译
- C# 文件操作 把文件读取到字节数组
- C#中Invoke的用法
- C#笔记(二)
- C# 调用cmd命令
- C# LDAP认证登录类参考