ResourceBundle.getBundle文件路径问题

我在jar里读取.properties文件时,总是找不到文件路径,后来用ResourceBundle读取.properties文件即可避免路径问题,代码如下:

//process为文件名,切记不要加 .properties, URL是文件里的键名

ResourceBundle bundle = ResourceBundle.getBundle("com.ihandy.smsoc.app.process");
String url = bundle.getString("URL");

 

 

 

 

ResourceBundle rs = ResourceBundle.getBundle("org.hello");//这里说明,hello文件就是在于classpath底下的,org包底下有这个文件hello.properties~

 

 

示例

 

props = new Properties();
props.load(new FileInputStream("src/conf/msf.properties"));//在工程底下src 目录的conf目录下

 

System.out.println(System.getProperty("user.dir"));  //这个是去工程的绝对路径的

 


 System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));

 

//这个是去当前classpath的uri的!

 

 

 

new Properties().load(new FileInputStream("test.properties"));//这里说明test文件在工程的跟目录下!

 

 

 

new Properties().load(new FileInputStream("test/test.properties"));//说明,在工程底下的test的文件夹底下的文件test.properties!

 


[转载]ResourceBundle的路径问题 <wbr>.properties文件路径 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值