Reputation: 222
I'm trying to learn how to use streams in PowerShell. I've been able to understand all of the methods in StreamReader except the Read(char[], In32, In32).
I've only been able to get this method to work using
[char[]]$ca = 'a','b','c','d','e'
$reader = [System.IO.StreamReader]::new($inputFile)
$reader.Read($ca,0,$ca.Length)
$reader.Close()
My question is how can use the Read method without creating an array before hand? Do I have to create and array of 1024 chars if That is the amount of data I want to read into the buffer?
Thanks
Upvotes: 2
Views: 2917
Reputation: 174690
You will have to create the buffer array beforehand, but you don't need to initialize it:
$ca = [char[]]::new(1024)
$reader = [System.IO.StreamReader]::new($inputFile)
$reader.Read($ca,0,$ca.Length)
$reader.Close()
Upvotes: 2