.net - 有没有办法在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
==================================================== =======================
解决方案
你试过这个吗?
[System.Io.File]::ReadAllText($sourcePath) | Out-File -FilePath $destinationPath -Encoding UTF8
使用 .NET 类应该更快。
推荐阅读
- java - jmap没有file参数,所以执行异常。但是添加file参数后执行正常
- javascript - 即使传递了正确的参数,node.js writeFileSync 也会引发错误
- python - 将 spark 数据帧列表保存到 pyspark 中的多个 csv 文件
- apache - htaccess 使用 GET 参数重定向 URL
- c# - .net core api 调用中的连接重置问题 (net::ERR_CONNECTION_RESET 200 (OK))
- python - 在满足python中的所有条件后添加一个新列
- php - 如何在wordpress的菜单中隐藏子类别并只保留类别?
- c++ - C++中指针类型的限制
- c++ - 如何在 C++ 的二维数组中进行切片操作,与 Python 相同
- arrays - 单击like按钮后,我想重新加载特定的 UITableView 行