I am modifying dummy file a.gradle which in on my desktop and then trying to replace it with actual Github project's gradle file under git directory on my local machine using below PowerShell command
Get-Content "a.gradle" -replace 'foo', 'bar'| Out-File "b.gradle"
But When I tried to run gradlw test command it is throwing an error:
unexpected char: 0x0 @ line 1, column 4.
??a p p l y p l u g i n : ' j a v a '
I tried appending "encoding "UTF8" after Out-File command but it is not working.
Out-File/>, as of PSv5.1, create "Unicode" (UTF16-LE) files by default, where each character is represented by (typically) 2 bytes.-Encoding UTF8produces UTF-8, but invariably prepends a BOM to the output file. Most Unix-heritage utilities can't handle either, and expect UTF-8 without a BOM. The question linked to by @JamesQMurphy has answers with solutions.System.IO.Fileclass or use the-NoNewLineparameter when available.