[英]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. test.txt是UTF-8编码的。 The problem is that when I run this task
问题是当我运行此任务时
it corrupts some UTF-8 symbols (only few of them, not all). 它破坏了一些UTF-8符号(只有少数,不是全部)。
I've tried to use ant -Dfile.encoding=UTF-8 -buildfile=build.xml
, 我尝试使用
ant -Dfile.encoding=UTF-8 -buildfile=build.xml
,
and specified build.xml encoding <?xml version="1.0" encoding="UTF-8">
, 并指定了build.xml编码
<?xml version="1.0" encoding="UTF-8">
,
but the problem remains. 但是问题仍然存在。
How can I make my Ant task work correctly with UTF-encoded files? 如何使我的Ant任务能够正确处理UTF编码的文件?
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默认值:否-默认为默认的JVM编码
So it's using the platform default encoding. 因此,它使用的是平台默认编码。 If you want it to use UTF-8, just change your call to:
如果您希望它使用UTF-8,只需将您的呼叫更改为:
<replace file="test.txt" token="smth" value="anything"
encoding="UTF-8" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.