在ANT中将文件转换为UTF-8而不使用BOM

时间:2017-09-22 09:30:27

标签: encoding utf-8 ant byte-order-mark

我有一些UTF-8 BOM编码的js文件。我想使用ant将这些文件转换为UTF-8编码。我使用了这个

copy任务
<copy todir="./custom_plugins" overwrite="true" outputencoding="UTF-8">
    <fileset dir="../plugins" />
</copy>

现在,当我在notepad ++中打开UTF-8 BOM中的文件时,它会以ANSI格式显示其编码,但这也会在文件的开头附加字符。

即使我尝试了this,但也没有工作。 我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

将这些文件编码为UTF-8后,我使用replaceregexp ant任务删除/替换带有空字符串的BOM字符\xEF\xBB\xBF

<replaceregexp match="\xEF\xBB\xBF" replace="" byline="true" encoding="UTF-8">
    <fileset dir="./custom_plugins">
        <include name="**/*.js"/>
    </fileset>
</replaceregexp>