就运行时性能而言,这是powershell中将大量文本写入文件的最快方法?
答案 0 :(得分:3)
Guillaume Bordier写了一篇很好的article关于写入文件的不同方法。
从文章的结论:
Method - Time to completion
‘>>’ - 29 s
Out-file and [Array] - 27 s
export-csv - 22 s
StreamWriter - 1.5 s
写入文件的最快方式(通过边距)使用StreamWriter
。
答案 1 :(得分:2)
$sw = new-object system.IO.StreamWriter(<my file path>)
$sw.write(<my large body of text>)
$sw.close()