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 文件
基础教程推荐
- 多个组件的复杂布局 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
