实现一个 TextReader,使其以一种特定的编码从字节流中读取字符。

 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);
}
}
}

构造函数

StreamReader(Stream)

为指定的流初始化 StreamReader 类的新实例。

StreamReader(Stream, Boolean)

用指定的字节顺序标记检测选项,为指定的流初始化 StreamReader 类的一个新实例。

StreamReader(Stream, Encoding)

用指定的字符编码为指定的流初始化 StreamReader 类的一个新实例。

StreamReader(Stream, Encoding, Boolean)

为指定的流初始化 StreamReader 类的新实例,带有指定的字符编码和字节顺序标记检测选项。

StreamReader(Stream, Encoding, Boolean, Int32)

为指定的流初始化 StreamReader 类的新实例,带有指定的字符编码、字节顺序标记检测选项和缓冲区大小。

StreamReader(Stream, Encoding, Boolean, Int32, Boolean)

为指定的流初始化 StreamReader 类的新实例,带有指定的字符编码、字节顺序标记检测选项和缓冲区大小,有选择性的打开流。

StreamReader(String)

为指定的文件名初始化 StreamReader 类的新实例。

StreamReader(String, Boolean)

为指定的文件名初始化 StreamReader 类的新实例,带有指定的字节顺序标记检测选项。

StreamReader(String, Encoding)

用指定的字符编码,为指定的文件名初始化 StreamReader 类的一个新实例。

StreamReader(String, Encoding, Boolean)

为指定的文件名初始化 StreamReader 类的新实例,带有指定的字符编码和字节顺序标记检测选项。

StreamReader(String, Encoding, Boolean, Int32)

为指定的文件名初始化 StreamReader 类的新实例,带有指定字符编码、字节顺序标记检测选项和缓冲区大小。

字段

Null

空流周围的 StreamReader

属性

BaseStream

返回基础流。

CurrentEncoding

获取当前 StreamReader 对象正在使用的当前字符编码。

EndOfStream

获取一个值,该值表示当前的流位置是否在流的末尾。

方法

Close()

关闭 StreamReader 对象和基础流,并释放与读取器关联的所有系统资源。

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(Inherited from MarshalByRefObject)

DiscardBufferedData()

清除内部缓冲区。

Dispose()

释放由 TextReader 对象使用的所有资源。

(Inherited from TextReader)

Dispose(Boolean)

关闭基础流,释放 StreamReader 使用的未托管资源,同时还可以根据需要释放托管资源。

Equals(Object)

确定指定的对象是否等于当前对象。

(Inherited from Object)

GetHashCode()

作为默认哈希函数。

(Inherited from Object)

GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。

(Inherited from MarshalByRefObject)

GetType()

获取当前实例的 Type

(Inherited from Object)

InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。

(Inherited from MarshalByRefObject)

MemberwiseClone()

创建当前 Object 的浅表副本。

(Inherited from Object)

MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(Inherited from MarshalByRefObject)

Peek()

返回下一个可用的字符,但不使用它。

Read()

读取输入流中的下一个字符并使该字符的位置提升一个字符。

Read(Char[], Int32, Int32)

从当前流中将指定的最多个字符读到指定索引位置开始的缓冲区。

ReadAsync(Char[], Int32, Int32)

从当前流中异步读取指定的最大字符,并且从指定的索引位置开始将该数据写入缓冲区。

ReadBlock(Char[], Int32, Int32)

从当前流中读取指定数目的字符并从指定索引开始将该数据写入缓冲区。

ReadBlockAsync(Char[], Int32, Int32)

从当前流中异步读取指定的最大字符,并且从指定的索引位置开始将该数据写入缓冲区。

ReadLine()

从当前流中读取一行字符并将数据作为字符串返回。

ReadLineAsync()

从当前流中异步读取一行字符并将数据作为字符串返回。

ReadToEnd()

从流的当前位置到末尾读取所有字符。

ReadToEndAsync()

异步读取从当前位置到流的结尾的所有字符并将它们作为一个字符串返回。

ToString()

返回表示当前对象的字符串。

(Inherited from Object)

IDisposable.Dispose()

有关此成员的说明,请参见 Dispose()

(Inherited from TextReader)

C# System.IO.StreamReader的更多相关文章

  1. 详解C#中System.IO.File类和System.IO.FileInfo类的用法

    System.IO.File类和System.IO.FileInfo类主要提供有关文件的各种操作,在使用时需要引用System.IO命名空间.下面通过程序实例来介绍其主要属性和方法. (1) 文件打开 ...

  2. 使用匿名管道在进程间通信 (System.IO.Pipes使用)(转)

    原文地址:http://www.cnblogs.com/yukaizhao/archive/2011/08/04/system-io-pipes.html 管道的用途是在同一台机器上的进程之间通信,也 ...

  3. System.IO

                 I/O       1.文件操作:File (1)void AppendAllText(string path, string contents) (2)bool Exist ...

  4. C# System.IO.StreamWriter

    实现一个 TextWriter,使其以一种特定的编码向流中写入字符. using System; using System.Collections.Generic; using System.Linq ...

  5. C# System.IO和对文件的读写操作

      System.IO命名空间中常用的非抽象类 BinaryReader 从二进制流中读取原始数据 BinaryWriter 从二进制格式中写入原始数据 BufferedStream 字节流的临时存储 ...

  6. C# System.IO.File

    using System; using System.IO; class Test { public static void Main() { string path = @"c:\temp ...

  7. winform 保存文件 打开文件 选择文件 字体样式颜色(流 using System.IO;)

    string filePath = ""; private void 保存SToolStripMenuItem_Click(object sender, EventArgs e) ...

  8. .net System.IO之Stream的使用详解

    本篇文章是对.Net中System.IO之Stream的使用进行了详细的分析介绍,需要的朋友参考下 Stream在msdn的定义:提供字节序列的一般性视图(provides a generic vie ...

  9. 利用System.IO.Compression操作压缩文件

    引用: using System.IO.Compression; using (FileStream zipToOpen = new FileStream(@"D:\json.zip&quo ...

随机推荐

  1. 使用aws中国的s3时,制订bucket poicy时注意注意……

    { "Version": "2012-10-17", "Statement": [ { "Sid": "Pub ...

  2. c#中的委託,匿名方法和lambda表達式

    (原博)http://www.cnblogs.com/niyw/archive/2010/10/07/1845232.html 简介 在.NET中,委托,匿名方法和Lambda表达式很容易发生混淆.我 ...

  3. 利用图片的灰度平均值来进行分类实现手写图片识别(数据集50000张图片)——Jason niu

    from collections import defaultdict import mnist_loader def main(): training_data, validation_data, ...

  4. hdu 4725 The Shortest Path in Nya Graph 【拆点】+【最短路】

    <题目链接> <转载于  >>> > 题目大意: 每个点放在一层,然后给了n个点,相邻的两层距离是固定的c,有额外m条无向边,然后求1到n的最短路径,如果没有 ...

  5. 002.Zabbix简介

    一 Zabbix简介 1.1 概述 Zabbix是一个企业级的高度集成开源监控软件,提供分布式监控解决方案.可以用来监控设备.服务等可用性和性能. 1.2 所支持监控方式 目前由zabbix提供包括但 ...

  6. Intellij IDEA 解决 Maven 依赖下载慢的问题

    最近用 IDEA 导入 Hadoop 源码, 但下载依赖特别慢.导致经常需要重启 IDEA 并且下载的过程非常艰难, 网上找了一些方法,各种尝试,终于解决了这个问题.本篇文章总结最关键的两点,希望能帮 ...

  7. 自定义Map.Entry的Comperator实现字符频率降序排序

    leetCode (#451,middle) java实现 class Solution { public String frequencySort(String s) { Map<Charac ...

  8. Windows下更改MySQL 数据库文件存放位置

    更改默认的mysql数据库目录 将 C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\data 改 ...

  9. Stanford CoreNLP使用需要注意的一点

    1.Stanford CoreNLP maven依赖,jdk依赖1.8 <dependency> <groupId>edu.stanford.nlp</groupId&g ...

  10. [数学] 奇异值分解SVD的理解与应用

    看一个预测的代码,在预处理数据的时候使用了svd.了解了一下svd相关资料,比较喜欢第一篇文章的解释,不过第二篇也很简单. https://blog.csdn.net/ab_use/article/d ...