使用Apache Ant,我希望我的属性文件输出
blurb=test\n\
但是有了这个,\ n \将在构建过程中逃避斜杠
<propertyfile file="about.properties">
<entry key="blurb" value="test\n\"/>
</propertyfile>
所以输出将是
blurb=test\\n\\
哪个不对
您可以使用内置的\n
属性使用propertyfile
任务回显文字字符串line.separator
。但是,如果在非Unix系统上运行脚本,这将产生不同的输出,例如\r\n
。
<propertyfile file="about.properties">
<entry key="blurb" value="test${line.separator}" />
</propertyfile>
结果:
#Thu, 07 Mar 2019 10:33:16 -0800
blurb=test\n
关于尾随反斜杠,这是不可能的,因为propertyfile
任务不只是盲目地将字符串回送到文件中;它主动维护属性文件并应用自动格式化。一个尾随的转义字符只是被格式化为什么都没有,因为它之后没有任何东西可以逃脱它。
例如,如果手动创建以下属性文件:
blurb=test\n\
...然后运行以下代码:
<propertyfile file="buildNumber.properties">
<entry key="anotherProperty" value="anotherValue" />
</propertyfile>
你最终得到这个:
#Thu, 07 Mar 2019 10:42:43 -0800
blurb=test\n
anotherProperty=anotherValue
尽管脚本甚至没有对blurb
属性做任何事情,但反斜杠被删除了。
如果你真的,真的想将blurb=test\n\
写入你的文件由于某种原因,你可以使用replaceregexp
任务(或只是replace
任务,如果你确切知道现有的值将是这样):
<replaceregexp
file="about.properties"
match="blurb=.*"
replace="blurb=test\\\\n\\\"
/>