Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
问题描述
我正在开发一个小项目,我想为它使用国际化.问题是当我尝试使用带有西里尔符号的 .properties 文件时,文本显示为垃圾.当我对字符串进行硬编码时,它显示得很好.
I'm developing a small project and I'd like to use internationalization for it. The problem is that when I try to use .properties file with cyrillic symbols inside, the text is displayed as rubbish. When I hard-code the strings it's displayed just fine.
这是我的代码:
ResourceBundle labels = ResourceBundle.getBundle("Labels");
btnQuit = new JButton(labels.getString("quit"));
在我的 .properties 文件中:
And in my .properties file:
退出 = Изход
我得到了垃圾.当我尝试
And I get rubbish. When i try
btnQuit = new JButton("Изход);
显示正确.据我所知,UTF-8 是用于文件的编码.
It is displayed correctly. As far as I am aware, UTF-8 is the encoding used for the files.
有什么想法吗?
推荐答案
AnyEdit 是一个eclipse-插件,可让您轻松地将属性文件从 unicode 符号转换为 unicode 符号.(避免使用像 native2ascii 这样的命令行工具)
AnyEdit is an eclipse-plugin that allows you to easily convert your your properties files from and to unicode notation. (avoiding the use of command-line tools like native2ascii)
如果您使用的是 Properties 单独的类(没有资源包),从 Java 1.6 开始,您可以选择 用自定义编码加载文件,使用 Reader(而不是 InputStream)
If you were using the Properties class alone (without resource bundle), since Java 1.6 you have the option to load the file with a custom encoding, using a Reader (rather than an InputStream)
我猜你也可以使用 new PropertyResourceBundle(reader),而不是 ResourceBundle.getBundle(..),其中 reader 是:
I'd guess you can also use new PropertyResourceBundle(reader), rather than ResourceBundle.getBundle(..), where reader is:
Reader reader = new BufferedReader(new InputStreamReader(
getClass().getResourceAsStream("messages.properties"), "utf-8")));
这篇关于在 Eclipse 项目中使用西里尔文 .properties 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Eclipse 项目中使用西里尔文 .properties 文件
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
