ResourceBundle

程序如下:  
  import   java.util.ResourceBundle;  
  import   java.util.Enumeration;  
  public   class   PropertyFile   {  
          public   PropertyFile()   {  
          }  
   
          public   void   readPropertyFile()   {  
                  ResourceBundle   bundle   =  
                                  ResourceBundle.getBundle("f:/pro/test.properties");  
          //   Enumerate   contents   of   resource   bundle  
          //The   next   two   lines   should   be   in   one   line.  
                  for   (Enumeration   props   =   bundle.getKeys();  
                                                                    props.hasMoreElements();   )   {  
                          String   key   =   (String)   props.nextElement();  
                          process(key,   bundle.getObject(key));  
   
                  }  
          }  
          public   void   process(String   pKey,Object   pValue){  
                  System.out.println("the   key   =   "+pKey+";   the   value   =   "+pKey.toString());  
          }  
   
          public   static   void   main(String[]   args){  
                  PropertyFile   test   =   new   PropertyFile();  
                  test.readPropertyFile();  
          }  
          }   
   
出错:  
  Exception   in   thread   "main"   java.util.MissingResourceException:   Can't   find   bundle   for   base   name   f:/pro/test,   locale   en_US  
   
  at   java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:837)  
   
  at   java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:806)  
   
  at   java.util.ResourceBundle.getBundle(ResourceBundle.java:550)  
   
  at   fileOperation.PropertyFile.readPropertyFile(PropertyFile.java:10)  
   
  at   fileOperation.PropertyFile.main(PropertyFile.java:27)   
   
1:ResourceBundle.getBundle   不用写.properties扩展名,只写了文件名,把文件放在根目录下就可以

2:如果写路径,把/换成转义符 //

 ResourceBundle.getBundle("f://pro//test.properties");  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值