资源绑定器

 1 package com.bjpowernode.java.reflect;
 2 
 3 import java.util.ResourceBundle;
 4 
 5 /*
 6 java.util包下提供了一个资源绑定器,便于获取属性配置文件中的内容。
 7 使用以下这种方式的时候,属性配置文件xxx.properties必须放到类路径下。
 8  */
 9 public class ResourceBundleTest {
10     public static void main(String[] args) {
11 
12         // 资源绑定器,只能绑定xxx.properties文件。并且这个文件必须在类路径下。文件扩展名也必须是properties
13         // 并且在写路径的时候,路径后面的扩展名不能写。
14         //ResourceBundle bundle = ResourceBundle.getBundle("classinfo2");
15 
16         ResourceBundle bundle = ResourceBundle.getBundle("com/bjpowernode/java/bean/db");
17 
18         String className = bundle.getString("className");
19         System.out.println(className);
20 
21     }
22 }

 

posted @ 2021-08-03 17:01  guoyuxin3  阅读(100)  评论(0)    收藏  举报