PropertiesUtil 读取配置文件工具类
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 读取配置文件工具类的更多相关文章
- ConfigUtil读取配置文件工具类
ConfigUtil package com.sso.util; import java.io.FileNotFoundException; import java.io.IOException; i ...
- Java读取properties配置文件工具类
1. PropertyUtils.java package javax.utils; import java.io.InputStream; import java.util.Properties ...
- Java加载Properties配置文件工具类
Java加载Properties配置文件工具类 import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; ...
- CSharp读取配置文件的类(简单实现)
Reinventing the wheel 系列 CSharp 读取配置文件的类 简单实现(注意没有写) 本人对CS 不是很熟,库也不熟,所以到网上找个实现,并自己添加了点异常.如果只是读取信息,足够 ...
- POI读取excel工具类 返回实体bean集合(xls,xlsx通用)
本文举个简单的实例 读取上图的 excel文件到 List<User>集合 首先 导入POi 相关 jar包 在pom.xml 加入 <!-- poi --> <depe ...
- Asp.NetCore 读取配置文件帮助类
/// <summary> /// 读取配置文件信息 /// </summary> public class ConfigExtensions { public static ...
- spring读取配置文件PropertyPlaceholderConfigurer类的使用
这里主要介绍PropertyPlaceholderConfigurer这个类的使用,spring中的该类主要用来读取配置文件并将配置文件中的变量设置到上下文环境中,并进行赋值. 一.此处使用list标 ...
- 读取配置文件工具demo
//读取配置文件public class ResourcesUtils { /* * @description:根据属性获取文件名 * * @param:propertyName文件的属性名 * * ...
- 开发读取.properties 配置文件工具类PropertiesUtil
import java.io.IOException; import java.io.InputStream; import java.util.Properties; import org.juni ...
随机推荐
- 【转】Linux设备驱动之Ioctl控制
原文网址:http://www.cnblogs.com/geneil/archive/2011/12/04/2275372.html 大部分驱动除了需要具备读写设备的能力之外,还需要具备对硬件控制的能 ...
- linux 下RMAN备份shell脚本
RMAN备份对于Oracle数据库的备份与恢复简单易用,成本低廉.对于使用非catalog方式而言,将RMAN脚本嵌入到shell脚本,然后再通过crontab来实现中小型数据库数据库备份无疑是首选. ...
- 手动编译Spring4.2源码,以及把源码导入myEclipse中
前提条件,先在本地配置好JDK1.8, 安装好Git 执行下面命令: 1,双击Git Bash, 进入源码存放路径 cd E:\Foler 2,git clone git@github.com:spr ...
- Web Developer可以做得更多
美国雅虎前端工程师Hedger Wang.这位原雅虎奇摩的第一位Web Developer,非常慷慨的与我们分享了他丰富的经验.现身说法,比空洞的理论更有感染力,我们发现现在遇到的很多问题也都是他曾经 ...
- jdbc操作数据库返回结果集的注意事项
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sq ...
- 利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用
Dixon 原文 用ArcGIS Engine.VS .NET和Windows控件开发GIS应用 此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署 ...
- Effective java笔记6--异常
充分发挥异常的优点,可以提高一个程序的可读性.可靠性和可维护性.如果使用不当的话,它们也会带来负面影响. 一.只针对不正常的条件才使用异常 先看一段代码: //Horrible abuse of ex ...
- 12、NFC技术:读写NFC标签中的Uri数据
功能实现,如下代码所示: 读写NFC标签的Uri 主Activity import cn.read.write.uri.library.UriRecord; import android.app.Ac ...
- 用Delphi实现文件关联
文件关联为我们带来很多的方便.Delphi自带有注册表对象TRegistry,可以通过它取得或改变注册表相关键值的内容. Function GetAssociatedExec(FileExt: S ...
- Cocos2d-android (05) 渐变动画(颜色,淡入淡出。。。)
淡入淡出.颜色渐变及动作重复执行 import org.cocos2d.actions.base.CCRepeatForever; import org.cocos2d.actions.interva ...