Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PowerShell上使用ANSI编码实例化System.IO.StreamWriter?_Powershell_Streamwriter - Fatal编程技术网

如何在PowerShell上使用ANSI编码实例化System.IO.StreamWriter?

如何在PowerShell上使用ANSI编码实例化System.IO.StreamWriter?,powershell,streamwriter,Powershell,Streamwriter,我没有创建Power Shell脚本的经验,我正在尝试实例化System.IO.StreamWriter类以提供特定的文本编码。我正在尝试这样做: $file = New-Object System.IO.StreamWriter("sample.txt", [System.Text.Encoding]::Default, 4096) 我收到以下错误消息: New-Object : Cannot find an overload for "StreamWriter" and the argum

我没有创建Power Shell脚本的经验,我正在尝试实例化System.IO.StreamWriter类以提供特定的文本编码。我正在尝试这样做:

$file = New-Object System.IO.StreamWriter("sample.txt", [System.Text.Encoding]::Default, 4096)
我收到以下错误消息:

New-Object : Cannot find an overload for "StreamWriter" and the argument count: "3". 
At line:1 char:18 
    + $out = New-Object <<<<  System.IO.StreamWriter("sample.txt", [System.Text.Encoding]::Default, 4096)
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
新对象:找不到“StreamWriter”的重载和参数计数:“3”。
第1行字符:18

+$out=New Object您正试图调用
StreamWriter(字符串、编码、Int32)
-但该签名不存在。诚然,错误消息还有一点不尽如人意。。。但基本上您需要自己创建流,或者使用。

第一个ctor参数是流,而不是字符串。@JohnC:没错。但是OP试图传递的第一个参数是字符串。这是我的观点。