我的程序如下:
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 这个文件存在
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 这个文件存在
这个异常的出现就说明没有找到这个文件啊。或者是文件的格式不对?