代码:
Locale myLocale = Locale.getDefault(Locale.Category.FORMAT);
//读取属性文件常用到的ResourceBundle类
ResourceBundle rb = ResourceBundle.getBundle("jdbc.properties",myLocale);
Enumeration<String> keys = rb.getKeys();
while(keys.hasMoreElements()){
System.out.println(keys.nextElement());
}
String addr = rb.getString("jdbcUrl")+","
+rb.getString("username")+","
+rb.getString("password");
System.out.println(addr);
异常:
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name jdbc.properties, locale zh_CN
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1499)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1322)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:796)
at hua.path.MainPath.main(MainPath.java:48)
解决:将jdbc.properties改为jdbc即可。