通过资源绑定器读取配置文件

package com.fmg.reflect;

import java.util.ResourceBundle;

public class ResourceBundleTest02 {
    public static void main(String[] args) {
        ResourceBundle s = ResourceBundle.getBundle("Properties");
        String username = s.getString("username");
        System.out.println(username);
    }
}

资源绑定器能灵活的加载资源, 具有很大的实际作用

适用限制:

  1. 只能读取 src 下的资源文件

  2. 只能读取 properties结尾的配置文件, 且读取的时候, 不能写后缀名

 

posted @ 2021-06-22 21:35  深海里的星星i  阅读(75)  评论(0)    收藏  举报