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 文件
基础教程推荐
- Maven:无效的目标版本:10 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- JPA惰性列表上的流 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
