package org.konghao.basic.util;

 import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties; import org.apache.wicket.util.file.File;
import org.junit.Test; public class PropertiesUtil { private static Properties properties; private String proper_resource;
public void setProper_resource(String proper_resource) {
this.proper_resource = proper_resource;
} public PropertiesUtil(String proper_resource) {
this.proper_resource = proper_resource;
} public Map<String,String> getProperties(){
properties = getInstance();
try {
InputStream inputStream = PropertiesUtil.class.getClassLoader().getResourceAsStream(proper_resource);
properties.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
Map<String,String> regMap = new HashMap<String, String>();
regMap.put("appId", properties.getProperty("appId"));
regMap.put("appsecret", properties.getProperty("appsecret"));
regMap.put("base_url", properties.getProperty("base_url"));
regMap.put("weixin_token", properties.getProperty("weixin_token"));
return regMap;
} public static Properties getInstance(){
if(null == properties){
properties = new Properties();
}
return properties;
} public static Properties loadResource(String file){
properties = getInstance();
try {
InputStream inputStream = PropertiesUtil.class.getClassLoader().getResourceAsStream(file);
System.out.println(inputStream);
if(properties != null){
properties.load(inputStream);
}
} catch (IOException e) {
e.printStackTrace();
}
return properties;
} public static void main(String[] args) {
PropertiesUtil pu = new PropertiesUtil("weixin_basic.properties");
Map<String, String> propsMap = pu.getProperties(); for(Entry<String, String> entry : propsMap.entrySet()) {
System.out.println(("key: " + entry.getKey() + ", value: " + entry.getValue()));
} Properties properties = loadResource("weixin_basic.properties");
System.out.println(properties.getProperty("appId"));
}
}

PropertiesUtil 读取配置文件工具类的更多相关文章

  1. ConfigUtil读取配置文件工具类

    ConfigUtil package com.sso.util; import java.io.FileNotFoundException; import java.io.IOException; i ...

  2. Java读取properties配置文件工具类

    1.   PropertyUtils.java package javax.utils; import java.io.InputStream; import java.util.Properties ...

  3. Java加载Properties配置文件工具类

    Java加载Properties配置文件工具类 import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; ...

  4. CSharp读取配置文件的类(简单实现)

    Reinventing the wheel 系列 CSharp 读取配置文件的类 简单实现(注意没有写) 本人对CS 不是很熟,库也不熟,所以到网上找个实现,并自己添加了点异常.如果只是读取信息,足够 ...

  5. POI读取excel工具类 返回实体bean集合(xls,xlsx通用)

    本文举个简单的实例 读取上图的 excel文件到 List<User>集合 首先 导入POi 相关 jar包 在pom.xml 加入 <!-- poi --> <depe ...

  6. Asp.NetCore 读取配置文件帮助类

    /// <summary> /// 读取配置文件信息 /// </summary> public class ConfigExtensions { public static ...

  7. spring读取配置文件PropertyPlaceholderConfigurer类的使用

    这里主要介绍PropertyPlaceholderConfigurer这个类的使用,spring中的该类主要用来读取配置文件并将配置文件中的变量设置到上下文环境中,并进行赋值. 一.此处使用list标 ...

  8. 读取配置文件工具demo

    //读取配置文件public class ResourcesUtils { /* * @description:根据属性获取文件名 * * @param:propertyName文件的属性名 * * ...

  9. 开发读取.properties 配置文件工具类PropertiesUtil

    import java.io.IOException; import java.io.InputStream; import java.util.Properties; import org.juni ...

随机推荐

  1. mysql 添加索引后 在查询的时候是mysql就自动从索引里面查询了。还是查询的时候有单 独的参数查询索引?

    MYSQL在创建索引后对索引的使用方式分为两种:1 由数据库的查询优化器自动判断是否使用索引:2 用户可在写SQL语句时强制使用索引 下面就两种索引使用方式进行说明第一种,自动使用索引.数据库在收到查 ...

  2. ubuntu 切换工作区域

    在Ubuntu 13.04中,默认是不激活多桌面工作空间的,所以在之前的版本可以在启动器看到的那个像“田”字的“工作区切换器”图标没有了,始终只有一个桌面了.要激活工作空间,在system setti ...

  3. ArcEngine下投影坐标和经纬度坐标的相互转换

    jojojojo2002 原文 ArcEngine下投影坐标和经纬度坐标的相互转换 投影转经纬度 private IPoint PRJtoGCS( double x, double y) { IPoi ...

  4. [搜片神器]直接从DHT网络下载BT种子的方法

    DHT抓取程序开源地址:https://github.com/h31h31/H31DHTDEMO 数据处理程序开源地址:https://github.com/h31h31/H31DHTMgr DHT系 ...

  5. LR之面向目标场景

    1.目标类型 2.设置目标

  6. ctype库试运行

    from ctypes import * msvcrt=cdll.msvcrt message_string="Hello world!\n" msvcrt.wprintf(&qu ...

  7. jquery checkbox勾选取消勾选的诡异问题

    jquery checkbox勾选/取消勾选的诡异问题jquery checkbox勾选/取消勾选的诡异问题 <form>        你爱好的运动是?<input type=&q ...

  8. Javascript模块化开发-轻巧自制

    Javascript模块化开发-轻巧自制 一.前言现在javascript的流行,前端的代码越来越复杂,所以我们需要软件工程的思想来开发前端.模块化是必不可少的,这样不仅能够提高代码的可维护性.可扩展 ...

  9. Visual Studio 2010+Oracle 10g +NHibernate配置

    南京酷都面试,考官问:你知道NHibernate吗?瞬间我就急了:只听说过Hibernate,NHibernate是什么?还有其他问题也是不知道,所以后果就悲剧了. 自己做一个小系统,总是想如果数据量 ...

  10. Chapter14:重载运算符

    对于一个运算符函数来说,它或者是类的成员,或者至少含有一个类类型的参数. int operator+(int, int);//错误,不能为int重定义内置运算符 对于一个重载的运算符来说,其优先级和结 ...