我想通過網絡轉儲一個大字符串到一個文本文件,但我只是每秒64kbit左右。 閱讀一些關於寫文件的不同方法,並看到使用Streamwriter的例子非常快,但是這是寫入本地文件。Powershell改變.net streamwriter緩衝區大小
遇到此線程的建議是增加緩衝區大小。有誰知道如何在Powershell中做到這一點?
包括鏈接以供參考:
Writing to file using StreamWriter much slower than file copy over slow network
謝謝!
編輯
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines($PathToFile, $LargeTextMass, $Utf8NoBomEncoding, 0x10000)
Cannot find an overload for "WriteAllLines" and the argument count: "4".
編輯2:
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
$sw = new-object System.IO.StreamWriter "test2.txt", $false, $Utf8NoBomEncoding,0x10000
很像它在你鏈接的例子中解釋的方式。您正在使用必要的構造函數參數創建您的Streamwriter,在此例中爲流,編碼和緩衝區大小:https://msdn.microsoft.com/en-US/library/72d9f8d5(v=vs.110)。 aspx。或字符串,布爾,編碼和緩衝區大小:https://msdn.microsoft.com/en-us/library/0wf7ab94(v=vs.110).aspx –
第一次嘗試沒有工作得很好。也許我需要先創建它。 – PatrikJ
是的,您需要首先創建帶有參數的對象,例如:$ sw = new-object System.IO.StreamWriter $ path System.Text.Encoding.UTF8 $ false 10000.您可以使用以下命令創建.Net對象構造函數參數與新對象。 –