如何逐行读取文本文件 - .NET技术 / C#
来源:互联网 发布:会计师事务所 知乎 编辑:程序博客网 时间:2024/05/17 05:23
StreamReader sr =new StreamReader(@"D:\a.txt");int lineCount =0;while (sr.Peek()> 0){lineCount++;MessageBox.Show(lineCount.ToString()+ "行:"+ sr.ReadLine());}sr.Close();
- C# code
- using System;using System.IO;class Test{public static void Main(){try{// Create an instance of StreamReader to read from a file.// The using statement also closes the StreamReader. using (StreamReader sr = new StreamReader("TestFile.txt")){String line;// Read and display lines from the file until the end of// the file is reached. while ((line = sr.ReadLine()) != null){Console.WriteLine(line);}}}catch (Exception e){// Let the user know what went wrong. Console.WriteLine("The file could not be read:");Console.WriteLine(e.Message);}}}
http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx
StreamReader sr = new StreamReader(@"D:\a.txt");for(int i=0;i<4;i++) sr.ReadLine();string str = sr.ReadLine(); //内容1str = sr.ReadLine(); //内容2//……sr.Close();
0 0
- 如何逐行读取文本文件 - .NET技术 / C#
- 如何逐行读取文本文件
- 逐行读取文本文件
- J2ME逐行读取文本文件
- vc逐行读取文本文件
- C++ 逐行读取文本文件
- C++逐行读取文本文件
- 逐字、逐行、直接读取文本文件
- NET之C#读取文本文件
- 如何使用C#读取文本文件
- 如何使用C#读取文本文件
- VB读取文本文件的例子:逐行读取
- java逐行读取和写入文本文件txt
- 逐行读取文本文件的 shell 脚本
- C文件操作示例:逐行读取文本文件
- C++逐行读取文本文件的正确做法
- C++实现逐行从文本文件读取数据
- Unity发布WebGl逐行读取本地文本文件
- SPFA算法 (最短路)
- 教你如何科学使用google
- Cordova 开发属于自己的插件(plugin)
- HDU 1243 反恐训练营(最长公共子序列的变形)
- 测试英语
- 如何逐行读取文本文件 - .NET技术 / C#
- Oracle Instant Client(即时客户端) 安装与配置 PLSQL Developer
- hdu 1698 Just a Hook
- hdu 5373 The shortest problem
- 侧滑删除进阶(五)
- Func和委托零碎代码
- Android 详解第三方介质交互之NFC,并且实现读你的交通卡,酒店房卡,学生证!
- 推荐程序员去的网站
- hdu3697(贪心+暴力)