C#StreamReader类用于从流中读取字符串。它继承TextReader类。它提供read()和ReadLine()方法从流中读取数据。
using System; using System.IO; public class StreamReaderExample { public static void Main(string[] args) { FileStream f = new FileStream("e:\\output.txt", FileMode.OpenOrCreate); StreamReader s = new StreamReader(f); string line=s.ReadLine(); Console.WriteLine(line); s.Close(); f.Close(); } }
Hello C#
using System; using System.IO; public class StreamReaderExample { public static void Main(string[] args) { FileStream f = new FileStream("e:\\a.txt", FileMode.OpenOrCreate); StreamReader s = new StreamReader(f); string line = ""; while ((line = s.ReadLine()) != null) { Console.WriteLine(line); } s.Close(); f.Close(); } }
Hello C# this is file handling
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)