【发布时间】:2012-05-02 08:08:09
【问题描述】:
我没有创建 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
我查看了 MSDN 文档 StreamWriter Constructor (Stream, Encoding, Int32),其中包含三个参数的重载。
有人知道如何实例化指定编码的 System.IO.StreamWriter 吗?
谢谢,
【问题讨论】: