character-encoding - karaf配置属性乱码

标签 character-encoding osgi apache-karaf karaf

我实现了 org.osgi.service.cm.ManagedService 接口(interface)来获取 Karaf 配置。但是当我给属性赋予中文值时,就出现乱码了。最初etc文件夹中的文件都是latin1编码的。我尝试过设置utf-8编码,但是没有效果。谁能帮我吗?

最佳答案

在 Karaf 中,配置文件(即 etc/*.cfg)由 felix 子项目“fileinstall”处理。

fileinstall 尚不支持为配置指定自定义字符编码,它使用 Properties 类和 Properties.load(InputStream),其中记录:

The load(Reader) / store(Writer, String) methods load and store properties from and to a character based stream in a simple line-oriented format specified below. The load(InputStream) / store(OutputStream, String) methods work the same way as the load(Reader)/store(Writer, String) pair, except the input/output stream is encoded in ISO 8859-1 character encoding. Characters that cannot be directly represented in this encoding can be written using Unicode escapes as defined in section 3.3 of The Java™ Language Specification; only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings.

因此,您必须在 ISE-8859-1 中对文件进行编码并引用每个 UTF 字符,或者使用 xml 文件对配置文件进行编码。

关于character-encoding - karaf配置属性乱码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35691662/

相关文章:

character-encoding - 不确定网络爬虫是否正确读取我的网站

osgi - 无法在 CQ5 中发布 bundle

java - 已解析 OSGI 包上的 ClassNotFoundException

java - 不同形式的 Camel : Content based routing,

java - Karaf 中 PersistenceProviderImpl 的 ClassCastException

PHP/MySQL 编码

linux - 设置字符编码 在 Cygwin Shell 中读取多个字符集

vb.net - 在 VB.NET 中显示向下的三角形 ▼ (U+25BC)

java - OSGi kf 框架的引导类路径扩展支持

maven - 使用maven生成karaf功能时出现NoFileAssignedException异常