Encoding 为什么Ant在属性文件中添加相等的字符

Encoding 为什么Ant在属性文件中添加相等的字符,encoding,ant,properties-file,Encoding,Ant,Properties File,我有一个给定的属性文件,如下所示: firstvalue=1 secondvalue=hello 我使用此Ant脚本更改值: <propertyfile file="A.properties"> <entry key="firstvalue" value="2" /> </propertyfile> 我理解为什么Ant任务会添加带有日期的注释,但为什么Ant也会在第二行添加相等的符号 我认为这是由于编码文件造成的,因为我不能

我有一个给定的属性文件,如下所示:

firstvalue=1
secondvalue=hello
我使用此Ant脚本更改值:

    <propertyfile file="A.properties">
        <entry key="firstvalue" value="2" />
    </propertyfile>
我理解为什么Ant任务会添加带有日期的注释,但为什么Ant也会在第二行添加相等的符号

我认为这是由于编码文件造成的,因为我不能用我所有的属性文件重现问题,而只能用其他人手动创建的一些文件。在Ant中使用文件之前,有没有办法避免这种行为或修复编码

编辑: 这是我的属性文件,请参见带有联机hextump工具的脚本之前的内容: 文件名:A.properties mime类型:

0000-0010:  ef bb bf 0d-0a 66 69 72-73 74 76 61-6c 75 65 3d  .....fir stvalue=
0000-0020:  31 0d 0a 73-65 63 6f 6e-64 76 61 6c-75 65 3d 68  1..secon dvalue=h
0000-0024:  65 6c 6c 6f  

                                ello
和相同的文件之后:

file name: A.properties
mime type: 

0000-0010:  23 54 68 75-2c 20 32 31-20 4d 61 79-20 32 30 31  #Thu,.21 .May.201
0000-0020:  35 20 31 35-3a 32 31 3a-31 32 20 2b-30 32 30 30  5.15:21: 12.+0200
0000-0030:  0d 0a ef bb-bf 3d 0d 0a-66 69 72 73-74 76 61 6c  .....=.. firstval
0000-0040:  75 65 3d 32-0d 0a 73 65-63 6f 6e 64-76 61 6c 75  ue=2..se condvalu
0000-0049:  65 3d 68 65-6c 6c 6f 0d-0a                       e=hello. .

问题是文件前面的UTF-8编码字节顺序标记(ef bb ff)。属性文件始终以ISO8859-1编码,而不是UTF-8编码,因此这些文件不是有效的属性文件。我强烈建议修复属性文件(并使其他人切换到不会重新引入问题的编辑器),但如果需要短期解决方法,可以首先删除BOM表:

<copy file="A.properties" encoding="UTF-8" tofile="A.properties.tmp">
  <filterchain>
    <deletecharacters chars="&#xfeff;"/>
  </filterchain>
</copy>
<move file="A.properties.tmp" tofile="A.properties"/>

<propertyfile file="A.properties">
  <entry key="firstvalue" value="2" />
</propertyfile>


我会运行xxd(或者找到一些在线hextump工具)。否则,人们很难猜到这个问题。在执行脚本之前和之后,我都有文件的十六进制转储。谢谢,它按照我的意愿工作。正如您所说,我将修复所有属性文件,并告诉其他人使用一个不会产生任何问题的编辑器。
<copy file="A.properties" encoding="UTF-8" tofile="A.properties.tmp">
  <filterchain>
    <deletecharacters chars="&#xfeff;"/>
  </filterchain>
</copy>
<move file="A.properties.tmp" tofile="A.properties"/>

<propertyfile file="A.properties">
  <entry key="firstvalue" value="2" />
</propertyfile>