常见流的继承关系:

StreamReader
命名空间:“System.IO” 字节流
StreamReader : TextReader(读取有序字符)
- StreamReader 用于读取标准文本文件中的信息,而 Stream 类用于字节输入和输出。
- StreamReader 除非另外指定,否则默认为 UTF-8 编码。
- 如果使用属性获取当前字符编码,则 CurrentEncoding 该值在第一种方法之后才是可靠的 Read ,因为在首次调用方法之前不会进行编码自动检测 Read 。
- 默认情况下, StreamReader 不是线程安全的。 TextReader.Synchronized有关线程安全包装
实例化一个 StreamReader 对象并调用其 ReadAsync 方法以异步读取文件:
using System;
using System.IO;
using System.Threading.Tasks;
class Example
{
static async Task Main()
{
await

本文解析了System.IO命名空间中的StreamReader类,介绍了其实例化、属性(如BaseStream和CurrentEncoding)和方法(如ReadAsync和ReadLineAsync)的用法,重点讲解了异步读取文件和IDisposable接口的实践。
701

被折叠的 条评论
为什么被折叠?



