蚂蚁时间格式反斜杠问题

ant time format backslash issue

我有一个 ant build.xml 到 create/modify 一个带有以下标签的 version.properties 文件:

<propertyfile
            file="${version.file}" comment="Build version info">
            <entry key="buildDate" type="date" value="now" pattern="MM-dd-yyyy HH:mm:ss"/>

结果是这样的:

buildDate=01-28-2015 15\:49\:57

有没有办法消除结果中的这些反斜杠?

propertyfile 使用 java.util.Properties 对象将属性存储在文件中。来自 Properties#store() 的文档:

For the key, all space characters are written with a preceding \ character. For the element, leading space characters, but not embedded or trailing space characters, are written with a preceding \ character. The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded.

所以您不必担心反斜杠 - 如果在您的构建文件中读回属性文件,它们将被忽略。如果您出于某种原因绝对必须删除反斜杠,则需要解析文件并手动删除它们(例如使用某种正则表达式)。