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 ...
随机推荐
- Thrift——初学
是什么? Thrift是一个跨语言的服务部署框架最初由Facebook于2007年开发,2008年进入Apache开源项目.Thrift通过一个中间语言(IDL, 接口定义语言)来定义RPC的接口和数 ...
- android adt自带eclipse无法设置ndk路径(找不到NDK配置)
分步阅读 到android sdk官网下载r23版本的adt时自带的eclipse没有设置ndk路径的地方,通过Install New Software 发现无法更新,那么如何解决这个问题呢? 方便他 ...
- 【转】谈一谈PHP字串清除空格函数不安全
清除空格的方法是不安全的,部分原因是因为字符中的空格非常多,例如 "addslashes的问题在 于黑客 可以用0xbf27来代替单引号,而addslashes只是将0xbf27修改为0xb ...
- Codeforces Round #218 (Div. 2) C题
C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Yii 实现MySQL多库和读写分离
前段时间为SNS产品做了架构设计,在程序框架方面做了不少相关的压力测试,最终选定了YiiFramework,至于为什么没选用公司内部的PHP框架,其实理由很充分,公司的框架虽然是“前辈”们辛苦的积累, ...
- PreferenceActivity使用方法
public class MainActivity extends Activity { @Override protected void onCreate(Bundle save ...
- selenium python (十一)alert/confirm/prompt的处理(js中的弹出框)
webdriver中处理js所生成的alert.confirm以及prompt,采用switch_to_alert()方法定位到alert/confirm/prompt.然后使用text/accept ...
- 二叉树单色路径最长&&穿珠子
对树的操作,特别理解递归的好处. //对于一棵由黑白点组成的二叉树,我们需要找到其中最长的单色简单路径,其中简单路径的定义是从树上的某点开始沿树边走不重复的点到树上的 //另一点结束而形成的路径,而路 ...
- Delphi中BitBlt函数实现屏幕对象抓图
uses WinTypes, WinProcs, Forms, Controls, Classes, Graphics; function CaptureScreenRect( ARect: TRec ...
- java Study 基础 1
1.myEclipse 生成get.set,source>Generate getter and setter 2.Web servlet.HttpServlet.HttpServletRequ ...