Search notes:

System.IO.File: ReadAllBytes and WriteAllBytes

The methods ReadAllBytes and WriteAllBytes of the System.IO.File class read and write a byte array from/to a file.

PowerShell example

The following minimal PowerShell script creates a (PowerShell) byte array ($byte_array) whose elements contain the ASCII codes of «Hello world.» and the writes this array into a file.
[Byte[]] $byte_array = 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 46

[System.IO.File]::WriteAllBytes("$pwd/hello-world.txt", $byte_array)
Github repository .NET-API, path: /System/IO/File/ReadAllBytes-WriteAllBytes/WriteAllBytes.ps1
This script then reads the content of the file being created as byte array and then prints the value of each byte cast into a System.Char:
[Byte[]] $byte_array = [System.IO.File]::ReadAllBytes("$pwd/hello-world.txt")

foreach ($byte in $byte_array) {
   write-host ($byte -as [Char])
}
Github repository .NET-API, path: /System/IO/File/ReadAllBytes-WriteAllBytes/ReadAllBytes.ps1

See also

ReadAllText()

Index