JAVA中的资源绑定器
- 资源绑定器:
java.util包下提供了一个资源绑定器,便于获取属性配置文件中的内容
使用以下这种方式的时候,属性配置文件xxx.properties必须放到类路径下。 - 在写路径的时候,路径后面的扩展名不能写
public class ResourceBundleTest01 {
public static void main(String[] args) {
/*
资源绑定器:只能绑定.properties文件,并且这文件必须放到类路径下。
并且在写路径的时候,路径后面的扩展名不能写
*/
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("reflection/Test");
//通过key获取value
System.out.println(bundle.getString("MyClass"));
}
}