tsds
tsds

Reputation: 9010

Ant replace task corrupts symbols in UTF-8 file

I have the following ant task:

<target name="test">
    <replace file="test.txt" token="smth" value="anything"/>        
</target>

test.txt is UTF-8 encoded. The problem is that when I run this task
it corrupts some UTF-8 symbols (only few of them, not all).
I've tried to use ant -Dfile.encoding=UTF-8 -buildfile=build.xml,
and specified build.xml encoding <?xml version="1.0" encoding="UTF-8">,
but the problem remains.

How can I make my Ant task work correctly with UTF-encoded files?

Upvotes: 1

Views: 5513

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500065

From the docs for the replace task, in the list of attributes:

Attribute: encoding
Description: The encoding of the files upon which replace operates.
Default: No - defaults to default JVM encoding

So it's using the platform default encoding. If you want it to use UTF-8, just change your call to:

    <replace file="test.txt" token="smth" value="anything" 
             encoding="UTF-8" />        

Upvotes: 8

Related Questions