不带BOM的UTF8编码-PowerShell [英] UTF8 encoding without BOM - PowerShell

查看:238
本文介绍了不带BOM的UTF8编码-PowerShell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bat文件,在其中编码了一些CSV文件.问题是一旦编码完成(我猜是BOM字节),文件的开头就有一个字符.这个字符困扰我,导致编码后,我使用此文件生成数据库. 这是用于编码的行(在bat文件中):

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

有没有办法在没有BOM的情况下对文件进行编码(如果这是问题所在)?

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

谢谢!

推荐答案

我找到了解决方案. 只需更改此行:

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

这篇关于不带BOM的UTF8编码-PowerShell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆