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 文件


基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01