您现在的位置: 365建站网 > 365文章 > C#使用StreamReader读取打开文件和写入文件的方法

C#使用StreamReader读取打开文件和写入文件的方法

文章来源:365jz.com     点击数:996    更新时间:2017-08-19 09:59   参与评论

本文实例讲述了C#使用StreamReader读取文件的方法。分享给大家供大家参考。具体实现方法如下:

</>code

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace W
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. using (StreamReader sr = new StreamReader (@"c:\1.txt",Encoding.UTF8,true))
  14. {
  15. while (!sr.EndOfStream)
  16. {
  17. Console.WriteLine(sr.ReadLine());
  18. }
  19. }
  20. Console.WriteLine("读取完毕");
  21. Console.ReadKey();
  22. }
  23. }
  24. }

本文实例讲述了C#使用StreamWriter写入文件的方法。分享给大家供大家参考。具体实现方法如下:

</>code

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace W
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. using (StreamWriter sw = new StreamWriter (@"c:\1.txt",true,Encoding.UTF8))
  14. {
  15. for (int i = 0; i < 100; i++)
  16. {
  17. sw.WriteLine(i);
  18. }
  19. }
  20. Console.WriteLine("写入完毕!");
  21. }
  22. }
  23. }

希望本文所述对大家的C#程序设计有所帮助。

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

发表评论 (996人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号