属性文件中特殊字符的编码问题
我有一个使用 build.properties 文件的 ant 构建脚本。我有这样的事情:
release_type=debug
version_code=1
version_name=1.0.0
logo_text=This is German: special chars like ä or ö
我现在的问题是,我使用 logo_text
替换 xml 文件中的占位符,结果是 3 个构建中的 2 个垃圾,例如:
<string name="logo_text">"This is German: special chars like ää or ü."</string>
我有 3 个构建目标(每个使用他们自己的属性文件)并且它总是相同的 2 搞砸了,第三个被正确替换。
文本源始终是采用 UTF-8
编码的 build.properties,并且构建文件也使用 UTF-8
。我找不到两者有此问题的任何区别。
我如何用文本替换占位符:
<?xml version="1.0" encoding="UTF-8"?>
<project name="branding-builds">
<!-- code snipped -->
<copy todir="./${short_title}">
<fileset dir="./brandings/${short_title}">
<exclude name="**/*.png"/>
<exclude name="**/*.java"/>
</fileset>
<filterset>
<filter token="LOGO_TEXT" value="${logo_text}" />
</filterset>
</copy>
<!-- code snipped -->
</project>
信息:重写特殊字符以确保复制和粘贴不会弄乱并不能解决问题。
I have a ant build script that uses a build.properties file. There I have something like this:
release_type=debug
version_code=1
version_name=1.0.0
logo_text=This is German: special chars like ä or ö
My problem is now, that I use logo_text
to replace a placeholder in an xml file and the result is in 2 of 3 builds garbage like:
<string name="logo_text">"This is German: special chars like ää or ü."</string>
I have 3 build targets (each using their own properties file) and its always the same 2 get the mess up, the third one is correctly replaced.
The source of the text is always a build.properties which is UTF-8
encoded and the build file uses UTF-8
, too. I can't find any difference why the two have this issue.
How I replace the placeholder with the text:
<?xml version="1.0" encoding="UTF-8"?>
<project name="branding-builds">
<!-- code snipped -->
<copy todir="./${short_title}">
<fileset dir="./brandings/${short_title}">
<exclude name="**/*.png"/>
<exclude name="**/*.java"/>
</fileset>
<filterset>
<filter token="LOGO_TEXT" value="${logo_text}" />
</filterset>
</copy>
<!-- code snipped -->
</project>
Info: Rewriting the special chars to make sure that copy&paste didn't messed up didn't solve the issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
属性文件不应采用 UTF-8 编码。引用自 http://download.oracle.com/javase /6/docs/api/java/util/Properties.html:
A properties file should't be UTF-8 encoded. Quote from http://download.oracle.com/javase/6/docs/api/java/util/Properties.html: