Powershell System.IO.StreamReader Read method



我正在尝试学习如何在PowerShell中使用流。我已经能够理解StreamReader中的所有方法,除了Read(char[],In32,In32(。

我只能让这种方法使用

[char[]]$ca = 'a','b','c','d','e'    
$reader = [System.IO.StreamReader]::new($inputFile)
$reader.Read($ca,0,$ca.Length)     
$reader.Close() 

我的问题是如何在不事先创建数组的情况下使用 Read 方法? 我是否必须创建和数组 1024 个字符,如果这是我要读入缓冲区的数据量?

谢谢

您必须事先创建缓冲区数组,但不需要初始化它:

$ca = [char[]]::new(1024)
$reader = [System.IO.StreamReader]::new($inputFile)
$reader.Read($ca,0,$ca.Length)     
$reader.Close() 

最新更新