Russkyc.AttachedUtilities.FileStreamExtensions is a collection of filestream attached method utilities for .NET Standard, .NET Core, and .NET Framework.
//Dependency Import
using Russkyc.AttachedUtilities.FileStreamExtensions;
StreamRead - FileStream Reader.
.StreamRead()
- Returnsstring
of file content..StreamReadBytes()
- Returns file asbyte[]
array..StreamReadLines()
- Returnsstring[]
of file content lines..StreamListLines()
- ReturnsList<string>
of file content lines..StreamReadSplit()
- Returnsstring[]
of file contents split by separator..StreamListSplit()
- ReturnsList<string>
array of file contents split by separator.
StreamWrite - FileStream Writer.
.StreamCreate()
- Creates empty file..StreamWrite()
- Writes text to file. Returns file path..StreamWriteBytes()
- Writes bytes to file. Returns file path..StreamWriteLines()
- Writes text lines to file. Returns file path..StreamAppend()
- Appends text to file. Returns file path..StreamAppendLines()
- Appends text lines to file. Returns file path.
StreamRead Usage:
//File path
string path = @"C:\Testfile.txt";
//Reads file to byte array
byte[] file = path.StreamReadBytes();
//Reads file content
string content = path.StreamRead();
//Reads file content lines to array
string[] lines = path.StreamReadLines();
//Reads delimited file content to array
string[] words = path.StreamReadSplit();
//Reads delimited file content to array
string[] delimited = path.StreamReadSplit(',');
StreamWrite Usage:
//File path
string path = @"C:\Testfile.txt";
//Writes bytes to file
byte[] bytes = {};
path.StreamReadBytes(bytes);
//Creates file
path.StreamCreate();
//Writes text to file
string text = "Hello C#!"
path.StreamWrite(text);
//Appends text to file
string text = "New Text C#!";
path.StreamAppend(text);
//Writes lines to file
string lines = {"Hello Line 1","Hello Line 2","Hello Line 3"};
path.StreamWriteLines(lines);
//Appends lines to file
string lines = {"Hello Line 1","Hello Line 2","Hello Line 3"};
path.StreamAppendLines(lines);