【问题标题】:Converting files to UTF-8 without BOM in ANT在 ANT 中将文件转换为没有 BOM 的 UTF-8
【发布时间】:2017-09-22 09:30:26
【问题描述】:

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

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

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

即使我尝试过this,但还是不行。 我该如何解决这个问题?

【问题讨论】:

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


    【解决方案1】:

    将这些文件编码为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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-21
      • 2012-02-12
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      • 1970-01-01
      • 2014-02-11
      • 1970-01-01
      相关资源
      最近更新 更多