首页 > 解决方案 > 有没有办法在powershell中使用UTF8编码转换一个非常大的XML文件?

问题描述

我有一个大的 XML 文件(1.7 GB),我试图在导入 SQL 服务器之前对其应用 UTF-8 编码。使用powershell,转换时间已经超过1小时,系统完全没用,因为内存使用量最大。有人可以建议一种更有效的方式使用 powershell 来编码这个文件吗?那是因为我还有其他几个需要转换的文件。提前感谢您抽出宝贵时间回复。

这是目前采用的方法:

$sourcePath = "C:\Folder\myfile.xml"
$destinationPath = "E:\Folder\myfile.xml"
Write-Host "Converting $_"
$content = Get-Content $_.FullName
Set-content (Join-Path -Path $destinationPath -ChildPath $_) -Encoding UTF8 -Value $content

==================================================== =======================

标签: .netperformancepowershellencodingutf-8

解决方案


你试过这个吗?

[System.Io.File]::ReadAllText($sourcePath) | Out-File -FilePath $destinationPath -Encoding UTF8

使用 .NET 类应该更快。


推荐阅读