当前位置:网站首页>C# IO Stream 流(二)扩展类_封装器
C# IO Stream 流(二)扩展类_封装器
2022-06-25 22:03:00 【天马3798】
一、C# IO Stream 流扩展类
C#包括以下标准IO(输入/输出)类,可从不同的源(例如文件,内存,网络,隔离存储等)进行读取/写入。
流(Stream): System.IO.Stream 是一个抽象类,提供了将字节(读,写等)传输到源的标准方法。就像包装器类一样传输字节。需要从特定源读取/写入字节的类必须实现Stream类。
以下类继承Stream类,以提供从特定源读取/写入字节的功能:
FileStream:从物理文件读取字节或向物理文件写入字节,无论它是.txt,.exe,.jpg还是任何其他文件。FileStream派生自Stream类。
MemoryStream: MemoryStream读取或写入存储在内存中的字节。
BufferedStream: BufferedStream从其他Stream读取或写入字节,以提高某些I / O操作的性能。
NetworkStream: NetworkStream从网络套接字读取或写入字节。
PipeStream: PipeStream读取或写入来自不同进程的字节。
CryptoStream: CryptoStream用于将数据流链接到密码转换。


二、C# IO Stream 阅读器和写入器
1.字符串 阅读器和写入器
StreamReader:StreamReader是一个帮助程序类,用于通过使用编码值将字节转换为字符来从Stream读取字符。它可用于从不同的流(例如FileStream,MemoryStream等)中读取字符串(字符)。
StreamWriter:StreamWriter是一个帮助程序类,用于通过将字符转换为字节将字符串写入Stream。它可以用于将字符串写入不同的流,例如FileStream,MemoryStream等。
2.二进制 阅读器和写入器
BinaryReader:BinaryReader是用于从字节读取原始数据类型的帮助程序类。
BinaryWriter:BinaryWriter用二进制写原始类型。

上面的图像显示,FileStream 从物理文件中读取字节,然后 StreamReader 通过将这些字节转换为字符串来读取字符串。同样,StreamWriter 获取一个字符串并将其转换为字节,然后写入 FileStream,然后 FileStream 将字节写入一个物理文件。因此,FileStream 处理字节,StreamReader 和 StreamWriter 处理字符串。
三、常用整理
Stream是用于从不同来源传输字节的抽象类。它是所有其他类的基类,这些其他类将字节读/写到不同的源。
FileStream 类提供对物理文件的字节读写功能。
读写器类提供了从流类(FileStream,MemoryStream等)中读取字节并将字节转换为适当编码的功能。
StreamReader通过将字节转换为字符串,提供了一个辅助方法来从FileStream中读取字符串。StreamWriter提供了一种帮助程序方法,可以通过将字符串转换为字节来将字符串写入FileStream。
更多:
C#数组分组_C#数据分组_C# Linq分组使用整理
C# 中的可用类型_不可用类型_C#双问号_C#问号点_C# null不等于
边栏推荐
- After xampp restarts, the MySQL service cannot be started.
- 自定义QComboBox下拉框,右对齐显示,下拉列表滑动操作
- C. Yet Another Card Deck-Educational Codeforces Round 107 (Rated for Div. 2)
- 提取系统apk
- 社招两年半10个公司28轮面试面经(含字节、拼多多、美团、滴滴......)
- hiberate核心API/配置文件/一级缓存详解
- Share a downloaded osgeo4w64 Library Based on qgis3.10
- Reproduction of an implant found by Kaspersky that writes shellcode into evenlog
- 对卡巴斯基发现的一个将shellcode写入evenlog的植入物的复现
- 数据同步
猜你喜欢

QComboBox下拉菜单中有分隔符Separator时的样式设置

24class static member

#24class静态成员

1.8 billion pixel Mars panorama Ultra HD released by NASA, very shocking

Efr32bg22 ble module (low power Bluetooth communication module) at command test

#23class介绍

Xinchida nd04 nd04c nrf52832 (52810) ble module (low power Bluetooth communication module) at command test

28 rounds of interviews with 10 companies in two and a half years (including byte, pinduoduo, meituan, Didi...)

Database - mongodb

Qt 中文和英文分别使用不同的字体
随机推荐
Analysis on resource leakage /goroutine leakage / memory leakage /cpu full in go
Beacon realizes asset management and indoor positioning based on 5.2 ultra-low power Bluetooth module efr32 (bg22ax)
【AXI】解读AXI协议原子化访问
Go语言逃逸分析全纪录
库项目和App项目中清单文件的包名不要相同
B. Box Fitting-CodeCraft-21 and Codeforces Round #711 (Div. 2)
My vscode
Database - mongodb
28 rounds of interviews with 10 companies in two and a half years (including byte, pinduoduo, meituan, Didi...)
对卡巴斯基发现的一个将shellcode写入evenlog的植入物的复现
C. Fibonacci Words-April Fools Day Contest 2021
cookie、session、token
util. Collection and encapsulation of JS tool functions
The package name of the manifest file in the library project and the app project are not the same
[Axi] interpretation of Axi protocol disorder mechanism
golang Make a list of intervals with sequential numbers
jdbc常见异常及错误解决办法汇总
Kylin
指针强化与提高
When are the three tools used for interface testing?