当前位置:网站首页>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不等于
边栏推荐
- 23class introduction
- Graduation trip | recommended 5-day trip to London
- 漏刻有时API接口实战开发系列(13):小鹅通云服务PHP-API二维数组传参解决方案
- 对卡巴斯基发现的一个将shellcode写入evenlog的植入物的复现
- C. Fibonacci Words-April Fools Day Contest 2021
- How does excel translate Chinese words into English automatically? This formula teaches you
- Visual studio code create minimal web API (asp.net core)
- ACM. Hj16 shopping list ●●
- hiberate架构介绍及环境搭建(非常详细)
- konva系列教程2:绘制图形
猜你喜欢

Beacon realizes asset management and indoor positioning based on 5.2 ultra-low power Bluetooth module efr32 (bg22ax)

28 rounds of interviews with 10 companies in two and a half years (including byte, pinduoduo, meituan, Didi...)
![[Axi] interpretation of Axi protocol atomic access](/img/40/c742b861d92dfa2a1b27ae9ccc7a5d.png)
[Axi] interpretation of Axi protocol atomic access

CSDN add on page Jump and off page specified paragraph jump

指针强化与提高

Binary, hexadecimal, big end and small end

hiberate核心API/配置文件/一级缓存详解

CSDN添加页内跳转和页外指定段落跳转

毕业旅行 | 伦敦5日游行程推荐

Qtcreator formatting code
随机推荐
解决TypeError: Unicode-objects must be encoded before hashing
统计字符串中不同回文子序列的个数
流数据
excel如何实现中文单词自动翻译成英文?这个公式教你了
Graduation trip | recommended 5-day trip to London
QLabel 文字水平滚动显示
.user.ini文件导致的php网站安装问题
Informatics Orsay all in one 1353: expression bracket matching | Luogu p1739 expression bracket matching
Ble Low Power Bluetooth networking process and Bluetooth role introduction
音频基础知识以及PCM转WAV
golang Make a list of intervals with sequential numbers
社招两年半10个公司28轮面试面经(含字节、拼多多、美团、滴滴......)
Hibernate architecture introduction and environment construction (very detailed)
How to use drawing comparison function in CAD
先序线索二叉树
平衡二叉树AVL
Qt Utf8 与 Unicode 编码的互相转换, Unicode编码输出为格式为 &#xXXXX
YUV444、YUV422、YUV420、YUV420P、YUV420SP、YV12、YU12、NV12、NV21
二叉排序树
Leetcode (605) -- flower planting