当前位置:网站首页>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不等于
边栏推荐
- Leetcode (435) - no overlapping interval
- Kotlin null pointer bug
- Count the number of different palindrome subsequences in the string
- 后序线索二叉树
- CSDN添加页内跳转和页外指定段落跳转
- Go language escape analysis complete record
- B. Box Fitting-CodeCraft-21 and Codeforces Round #711 (Div. 2)
- Hbuilderx uses the gaude map to obtain the current location
- 18亿像素火星全景超高清NASA放出,非常震撼
- 流数据
猜你喜欢

经典图像分割网络:Unet 支持libtorch部署推理【附代码】

流数据

When are the three tools used for interface testing?

转载: QTableWidget详解(样式、右键菜单、表头塌陷、多选等)

Hibernate core api/ configuration file / L1 cache details

Use of xinchida ble 5.0 Low Power Bluetooth module (at command serial port transparent transmission) rsbrs02abr

What is Unified Extensible Firmware Interface (UEFI)?

Uni app -- listen for the exit of the return key

二进制、16进制、大端小端

CXF
随机推荐
golang Make a list of intervals with sequential numbers
RK3568+鸿蒙工控板工业网关视频网关解决方案
213.打家劫舍 II
[Axi] interpretation of Axi protocol atomic access
Anaconda一文入门笔记
Binary, hexadecimal, big end and small end
cookie、session、token
C. Fibonacci Words-April Fools Day Contest 2021
记录一下Qt将少量图片输出为MP4的思路及注意事项
Konva series tutorial 2: drawing graphics
24class static member
(serial port Lora module) centrida rf-al42uh private protocol test at instruction test communication process
解决‘tuple‘ object has no attribute ‘lower‘
流数据
B. Box Fitting-CodeCraft-21 and Codeforces Round #711 (Div. 2)
QComboBox下拉菜单中有分隔符Separator时的样式设置
hiberate架构介绍及环境搭建(非常详细)
期末复习【机器学习】
Go language escape analysis complete record
数据同步