Montag, 17. Oktober 2016

Write files without byte order mark (BOM)

If you use Out-File with -Encoding utf8 you invariably get a file where the first three bytes mark the byte order. This can break the further processing of the file, e. g. SQL+ is incapable to cope with it... why does Oracle support UTF-8 anyway ;-).
To get arround this, you can use [System.IO.File]::WriteAllLines with the proper encoding, e.g.
$UTF8NoBomEncoding = New-Object System.Text.UTF8Encoding(
      $False,
      $True)
[System.IO.File]::WriteAllLines(
      $outputFilePath,
      $array,
      $UTF8NoBomEncoding)

Keine Kommentare:

Kommentar veröffentlichen