Java配置文件Properties加载
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java配置文件Properties加载相关的知识,希望对你有一定的参考价值。
import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * Created by fubin on 2017/1/12 0012. * * * 配置文件加载与访问 * * */ public class PropertiesUtils { private static Properties PRO = new Properties(); static { InputStream ins = null; try { ins = PropertiesUtils.class.getResourceAsStream("/payConfig.properties"); PRO.load(ins); } catch (IOException e) { System.out.println("加载连连支付配置文件失败!"); e.printStackTrace(); } finally { try { ins.close(); } catch (IOException e) { e.printStackTrace(); } } } public static String getConfigValue(String key){ String value = PRO.getProperty(key); return value; } public static final String OID_PARTNER = getConfigValue("OID_PARTNER"); public static final String YT_PUB_KEY = getConfigValue("YT_PUB_KEY"); public static final String MD5_KEY = getConfigValue("MD5_KEY"); public static final String PLATFORM_DOMAIN = "new.vpfinance.cn"; public static final String NOTIFY_URL = getConfigValue("NOTIFY_URL"); public static final String RETURN_URL = getConfigValue("RETURN_URL"); public static final String PRI_KEY_VALUE = getConfigValue("PRI_KEY_VALUE"); public static final String SERVER = getConfigValue("SERVER"); public static final String TRADER_MD5_KEY = getConfigValue("TRADER_MD5_KEY"); public static final String CARD_AND_PAY_NOTIFY = getConfigValue("CARD_AND_PAY_NOTIFY"); public static final String CARD_AND_PAY_URL = getConfigValue("CARD_AND_PAY_URL"); public static void main(String[] args){ String value = PropertiesUtils.getConfigValue("TRADER_MD5_KEY"); System.out.println(value); System.out.println(PropertiesUtils.TRADER_MD5_KEY); } }
以上是关于Java配置文件Properties加载的主要内容,如果未能解决你的问题,请参考以下文章