用java自带的工具类ResourceBundle类读取.properties配置文件的工具类

来源:互联网 发布:阿里云智慧农业平台 编辑:程序博客网 时间:2024/05/29 02:32
#配置文件名字exam.propertiesstudent_load_path=http://127.0.0.1:8989/exam2/



//工具类读取配置文件public class Configuration {       final static String file = "exam";   //文件的名字       static ResourceBundle rb = null;    static {        try {            rb = ResourceBundle.getBundle(file);        } catch (Exception e) {            e.printStackTrace();        }    }    public static String getProperty(String key) {        String result = null;        try {            result = rb.getString(key);        } catch (Exception e) {             e.printStackTrace();        }        return result;    }}

//调用 public static void main(String args[]){    System.out.println("cc==" + Configuration.getProperty("down_question_word_path"));    }