Abstract [ Documentation]
The System.IO namespace contains types to:
- Read or write files
- Read or modify directories
- Read or write data streams
- Compress or decompress files
- Communicate via pipes and serial ports
Overview of Types for Files/Directories
| Type | Static or Instance methods | Description | 
|---|---|---|
| File | static | For manipulating files, creating FileStreamobjects | 
| FileInfo | instance | For manipulating files, creating FileStreamobjects | 
| Directory | static | For manipulating directories | 
| DirectoryInfo | instance | For manipulating directories | 
| Path | both | For manipulating paths | 
See Notes on File IO.
overview of types for streams
| Type | Use | 
|---|---|
| FileStream | Reading/writing a file | 
| IsolatedStorageFileStream | Reading/writing a file in isolated storage | 
| MemoryStream | Reading/writing to memory as a backing store | 
| BufferedStream | Improving performance of read/write operations | 
| NetworkStream | Reading/Writing over network sockets | 
| PipeStream | Reading/writing over anonymous and named pipes | 
| CryptoStream | Linking data streams to cryptographic transformations | 
See Notes on Streams.
overview of types for compression
From the System.IO.Compression namespace:
| Type | Use | 
|---|---|
| ZipArchive | Creating and retrieving compressed files in a zip archive | 
| ZipArchiveEntry | Representing a compressed file | 
| ZipFile | Creating, extracting and opening a compressed file | 
| ZipFileExtensions | Extensions for the above | 
| DeflateStream | Compressing and decompressing streams using the Deflate algorithm | 
| GZipStream | Compressing and decompressing streams using the gzip data format | 
See Notes on Compression and Decompression
Convenience vs. Control
Many of the APIs in the System.IO namespace can be placed on a spectrum of convenience vs control.
These APIs are listed from low level (most control) to high level (most convenient)
reading a text file
- File.OpenHandle+- RandomAccess.Read(most control)
- File.Open+- FileStream.Read`
- File.OpenText+- StreamReader.ReadLine
- File.ReadLines+- IEnumerable<string>
- File.ReadAllLines+- string[]
- File.ReadAllText+- string(most convenient)
reading json text
- Utf8JsonReader+- Pipelinesor- Stream(most control)
- JsonDocument+- Stream
- JsonSerializer+- Stream
- JsonSerializer+- string(most convenient)