前言
java.util包下提供了一个资源绑定器【ResourceBundle】,便于获取属性配置文件【Properties】中的内容。使用以下这种方式的时候,属性配置文件xxx.properties必须放到类路径下。
eg.
class ResourceBundleTest{
public static void main(String[] args) {
// 资源绑定器,只能绑定xxx.properties文件。并且这个文件必须在类路径下。文件扩展名也必须是properties
// 并且在写路径的时候,路径后面的扩展名不能写。
// ResourceBundle bundle = ResourceBundle.getBundle("reflectClassInfo2");
ResourceBundle bundle = ResourceBundle.getBundle("javase/reflectBean/db");
String className = bundle.getString("className");
System.out.println(className);
}
}
方法
方法 | 备注 |
---|---|
ResourceBundle.getBundle(“类路径下的文件地址【不包括文件扩展名】”) | 静态方法 |
注:
- 写路径的时候,路径后面的文件扩展名不能写。
- 只能绑定xxx.properties文件。
- 文件扩展名也必须是properties。