一个专门用来读取Properties文件的类ResourceBundle

461 阅读1分钟

在src下新建一个文件my_data.properties

name=kehao
country=china

用ResourceBundle 读取代码如下

public class ResourceBundleDemo {
    public static void main(String[] args) {
        ResourceBundle bundle = ResourceBundle.getBundle("my_data");
        String name = bundle.getString("name");
        String country = bundle.getString("country");
        System.out.println("name: "+name);
        System.out.println("country: "+country);
    }
}

运行结果:

name: kehao
country: china