ResourceBundle能否使用绝对路径?

yingtju 2008-09-09 02:34:47
看了API,没有设置路径的函数
只能放在classpath下吗?最终程序是这样的:
/home/run.bat
/config/message files
/lib/*.jar
用..\config\message取不出来
很想用它的依据本地locale自动使用对应文件的功能。
...全文
293 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yingtju 2008-09-11
  • 打赏
  • 举报
回复
这个什么意思?
相对路径也可由绝对路径变通转化

getBundle attempts to locate a property resource file.
It generates a path name from the candidate bundle name by
replacing all "." characters with "/" and appending the string ".properties".
It attempts to find a "resource" with this name using ClassLoader.getResource.

貌似得从ClassLoader.getResource下手,再去看看
rainsilence 2008-09-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 dracularking 的回复:]
getBundle方法本身貌似是不行的 只能用相对路径定位方式


Java codeprivatestaticfinalString DEFAULT_RESOURCE_PATH="resources.languages.resources";
ResourceBundle resourceBundle=ResourceBundle.getBundle(DEFAULT_RESOURCE_PATH, locale);

相对路径也可由绝对路径变通转化
然后在此 fully qualified base name of the resource bundle 所指定的路径下
放上标识语言所属的MyResources_xx.properties以及默认的My…
[/Quote]
正确
dracularking 2008-09-09
  • 打赏
  • 举报
回复
getBundle方法本身貌似是不行的 只能用相对路径定位方式


private static final String DEFAULT_RESOURCE_PATH
= "resources.languages.resources";
ResourceBundle resourceBundle
= ResourceBundle.getBundle(DEFAULT_RESOURCE_PATH, locale);


相对路径也可由绝对路径变通转化
然后在此 fully qualified base name of the resource bundle 所指定的路径下
放上标识语言所属的MyResources_xx.properties以及默认的MyResources.properties
即可自动对应吧
songzairan 2008-09-09
  • 打赏
  • 举报
回复
帮顶一个!关注ing...学习....
老紫竹 2008-09-09
  • 打赏
  • 举报
回复
当然可以。
内存泄漏 2008-09-09
  • 打赏
  • 举报
回复
没用过..占沙发帮你顶。。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧