相关疑难解决方法(0)

为什么Powershell文件串联将UTF8转换为UTF16?

我正在运行以下Powershell脚本,将一系列输出文件连接到一个CSV文件中.whidataXX.htm(其中xx是两位数的序号),创建的文件数因运行而异.

$metadataPath = "\\ServerPath\foo" 

function concatenateMetadata {
    $cFile = $metadataPath + "whiconcat.csv"
    Clear-Content $cFile
    $metadataFiles = gci $metadataPath
    $iterations = $metadataFiles.Count
    for ($i=0;$i -le $iterations-1;$i++) {
        $iFile = "whidata"+$i+".htm"
        $FileExists = (Test-Path $metadataPath$iFile -PathType Leaf)
        if (!($FileExists))
        {
            break
        }
        elseif ($FileExists)
        {
            Write-Host "Adding " $metadataPath$iFile
            Get-Content $metadataPath$iFile | Out-File $cFile -append
            Write-Host "to" $cfile
        }
    }
} 
Run Code Online (Sandbox Code Playgroud)

whidataXX.htm文件进行编码UTF8,但我的输出文件进行编码UTF-16.当我在记事本中查看文件时,它看起来是正确的,但是当我在十六进制编辑器中查看它时,Hex值00出现在每个字符之间,当我将文件拉入Java程序进行处理时,文件将打印到控制台额外的空间c h a r a c t e r s.

首先,这对PowerShell来说是正常的吗?或者源文件中是否存在导致此问题的内容? …

powershell utf-8 utf-16 data-conversion

10
推荐指数
1
解决办法
6601
查看次数

标签 统计

data-conversion ×1

powershell ×1

utf-16 ×1

utf-8 ×1