我的程序如下:
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)好像是需要设置什么东西。请问怎么设置阿
f:/pro/test.properties 这个文件存在

解决方案 »

  1.   

    MissingResourceException - if no resource bundle for the specified base name can be found
    这个异常的出现就说明没有找到这个文件啊。或者是文件的格式不对?
      

  2.   

    说明没有找到文件啊!ResourceBundle.getBundle 好像不用写.properties扩展名吧,只写文件名就可以了!你查查API看看,我记得以前只写了文件名,把文件放在根目录下就可以
      

  3.   

    ///getBundle("f:/pro/test.properties");这里的传入参数不是文件路径。你好像没有明白ResourceBundle的原理。