UTF8 encoding without BOM - PowerShell

给你一囗甜甜゛ 提交于 2019-12-08 00:42:38

问题


I have a bat file where I encode some CSV files. The problem is that there are one character at the begining of the file once the encoding have been done (BOM byte I guess). This character bothers me cause after encoding, I use this file to generate a database. Here is the line for encoding (inside bat file):

powershell -Command "&{ param($Path); (Get-Content $Path) | Out-File $Path -Encoding UTF8 }" CSVs\\pass.csv

Is there any way to encode the file without BOM (if this is the problem)??

Thanks!


回答1:


I found the solution. Just change the line with this:

powershell -Command "&{ param($Path); $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding($False); $MyFile = Get-Content $Path; [System.IO.File]::WriteAllLines($Path, $MyFile, $Utf8NoBomEncoding) }" CSVs\\pass.csv


来源:https://stackoverflow.com/questions/17699645/utf8-encoding-without-bom-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!