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 ...
随机推荐
- mysql添加用户和用户权限
Mysql添加用户使用可以对mysql数据库用户表有操作权限的用户名登陆mysqlinsert into user(Host,User,Password) values('%','name','pas ...
- 分享15款为jQuery Mobile定制的插件
jQuery Mobile 1.0 已经发布了, 做为jQuery的移动设备类库, 并且依靠着jQuery这个及其受欢迎的类库,必将带给大家不一样的使用体验,基于jQuery Mobile的插件开发必 ...
- 44、自定义仿IOS对话框
private Dialog myDialog = null; private void ExitLogin() { View view = LayoutInflater.from(MainActiv ...
- Loadrunner 性能指标定位系统瓶颈
判断CPU瓶颈 1, %processor time 平均值大于95 2, processor queue length大于2 (大于处理器个数+1).可以确定CPU瓶颈 3, CPU空闲时间为零(z ...
- JSON 教程学习进度备忘
书签:跳过:另外跳过的内容有待跟进 __________________ 学习资源:W3School. _________________ 跳过的内容: 1. ______________ 知识点:1 ...
- 1005acm罚时
ACM国际大学生程序设计竞赛是由国际计算机学会主办的,一项旨在展示大学生创新能力.团队精神和在压力下编写程序.分析和解决问题能力的年度竞赛.参赛队伍最多由三名参赛队员组成,竞赛中一般命题10-13题, ...
- CentOS下安装R
R的Windows版本有直接的安装包,直接下载安装很方便,但是对于CentOS6以上,不能直接通过yum 安装R,需要自己编译. 1. 在编译之前,用yum安装各种软件 (1)安装gcc > y ...
- 字符串和数组中split().toString(),join(),splice(),slice(),substr()和substring()
<!Doctype html> <head> <mate charset="utf-8"> <title>string change ...
- String内存陷阱简介
String 方法用于文本分析及大量字符串处理时会对内存性能造成一些影响.可能导致内存占用太大甚至OOM. 一.先介绍一下String对象的内存占用 一般而言,Java 对象在虚拟机的结构如下:•对象 ...
- ipc.Client: Retrying connect to server: h1/192.168.1.61:9000. Already tried 0 time(s);解决方法
1.检查namenode服务器的是否运行正常,我的问题是没有开启hadoop集群出现的. 2.检查namenode服务器的防火墙是否开放的响应端口,一般内网建议关闭.