将resourceBundle与外部文件一起使用java

编程入门 行业动态 更新时间:2024-10-10 20:16:07
本文介绍了将resourceBundle与外部文件一起使用java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在阅读其他问题和答案,但我没有得到资源边界如何工作完整。 我认为在Joomla中使用多语言选项的方式类似。 基本上,您有针对不同语言要阅读的不同消息的文件。 所以我在src / Lang文件夹中创建了System.properties 我创建内部

I have been reading other questions and answers around this but I am not getting how resource boundle works for completly. I think it is similar at Joomla way of using multilingual options. Basically you have files for the different messages you want to read for different languages. So I created System.properties inside my src/Lang folder Inside I create

STARTING_MYAPP=Starting my app

我可能在这里错了,但无论如何我无法读取默认文件。现在我脑子死了,我不能理解我读到的任何东西这就是我这样做的方式

I might be wrong here, but anyways I am not able to read the default file. Right now I am brain death, and I cant make sense of anything I read this is how I am doing this

Locale locale = Locale.getDefault(); String basename ="System"; ResourceBundle resourceBundle = ResourceBundle.getBundle(basename, locale); System.out.println(resourceBundle.getString("STARTING_MYAPP")); //UserPreferences UserPrefs = new UserPreferences();

当我调用getBundle()时,它有两个输入,basename和locale,right。我在使用basename时遇到问题。如果我的文件在src / lang / System.properties中,我该如何查找它。 basename =System,basename =Lang / System,basename =System.properties,basename =myProject.label。

when I call getBundle(),it has two inputs, the basename and the locale, right. I am having trouble with the basename. If my file is inside src/lang/System.properties, how should I look for it. basename="System", basename="Lang/System", basename="System.properties", basename="myProject.label".

我尝试了所有这一切和一些更多的组合,但没有工作,我总是得到像线程主java.util.MissingResourceException异常:无法找到基本名称系统的捆绑,locale en_US

I tried all of this and some more combinations but non work, I always get something like Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name System, locale en_US

关于语言环境,我如何将其保留为默认值,因此我不必使用System_en_US.properties或类似的东西。

About the locale, how I leave it up to default, so I dont have to use a System_en_US.properties or something like that.

推荐答案

basename的结构类似于完全限定的类名(因为资源包可以是类),所以如果你的类路径根是 src 和资源是一个文件 src / lang / System.properties ,然后基本名称是 lang.System 。

The basename is structured like a fully qualified class name (because resource bundles can be classes), so if your classpath root is src and the resource is a file src/lang/System.properties, then the basename is lang.System.

关于语言环境,我如何将它保留为默认值,所以我不必使用 System_en_US.properties或$ 就是这样。

About the locale, how I leave it up to default, so I dont have to use a System_en_US.properties or something like that.

只需使用 getBundle() 仅采用基本名称的方法。

Simply use the getBundle() method that takes only the basename.

更多推荐

将resourceBundle与外部文件一起使用java

本文发布于:2023-11-17 10:40:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609763.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   resourceBundle   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!