Using PowerShell to write a file in UTF-8 without the BOM

前端 未结 13 1345
名媛妹妹
名媛妹妹 2020-11-22 06:25

Out-File seems to force the BOM when using UTF-8:

$MyFile = Get-Content $MyPath
$MyFile | Out-File -Encoding \"UTF8\" $MyPath

13条回答
  •  时光取名叫无心
    2020-11-22 07:21

    Starting from version 6 powershell supports the UTF8NoBOM encoding both for set-content and out-file and even uses this as default encoding.

    So in the above example it should simply be like this:

    $MyFile | Out-File -Encoding UTF8NoBOM $MyPath
    

提交回复
热议问题