Java 读取 Properties文件信息

来源:互联网 发布:爱极客淘宝 编辑:程序博客网 时间:2024/06/07 03:35
 
package com.util;import java.util.Locale;import java.util.ResourceBundle;/** * @author public */ public class GetProperties {private ResourceBundle bundle = null;private String proName = ""; public GetProperties(String proname){this.proName = proname;}/** * 按照KEY获取配置文件中相应值 * @param type * @return 取其中的属性值(String类型) */public String getProp(String type) throws Exception {if (bundle == null) {try {bundle = ResourceBundle.getBundle(this.proName, Locale.getDefault());} catch (Exception e) {System.out.println("获取资源出错!" + e);}}return bundle.getString(type);}public static void main(String[] args){try {GetProperties gps = new GetProperties("dictionary");String test=gps.getProp("ftp");System.out.println("==>"+test);} catch (Exception e) {e.printStackTrace();}}}

原创粉丝点击