C#读取txt文件

分手后的思念是犯贱 2021-06-24 16:11 602阅读 0赞

继上一篇文章写到解压文件,将一个txt文件手动压缩成.rar文件,后用程序解压,现在再写一个程序将.txt文件内的内容读出来。
学习参考网址:
https://www.cnblogs.com/akwwl/p/3240813.html

读出.txt每一行的信息
代码:

  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 ReadText
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. StreamReader sr = new StreamReader("F:\\TestUnZip\\testUnzip.txt", Encoding.Default);
  14. String line;
  15. while ((line = sr.ReadLine()) != null)
  16. {
  17. Console.WriteLine(line.ToString());
  18. }
  19. Console.ReadLine();
  20. }
  21. }
  22. }

测试结果:

2789632-d9c620c1f6267cdc.png

读取txt每一行信息

2789632-3b18269684ea9294.png

公众号.png

发表评论

表情:
评论列表 (有 0 条评论,602人围观)

还没有评论,来说两句吧...

相关阅读