首页 > 编程语言 > 详细

java 获取properties配置文件属性值

时间:2015-03-23 21:50:16      阅读:327      评论:0      收藏:0      [点我收藏+]
package org.yingmm.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @ClassName: TemplateUtil
 * @Date:2015-1-14 下午12:06:46
 * @author yingmm
 * @description: 读取配置文件类
 */
public class TemplateUtil {

	private static Properties prop;
	private static TemplateUtil tu = new TemplateUtil();

	/** 文件名称 */
	private String proFileStr = "template";

	public TemplateUtil() {
		String templatePath = System.getProperty("user.dir") + File.separator + "src/" + proFileStr + ".properties";
		if (prop == null) {
			prop = new Properties();
			File f = new File(templatePath);
			FileInputStream in = null;
			try {
				in = new FileInputStream(f);
				prop.load(in);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static synchronized TemplateUtil getTemplateUtil() {
		if (prop == null) {
			tu = new TemplateUtil();
		}
		return tu;
	}

	public String getProperties(String key, String defaultVal) {
		return prop.getProperty(key) == null ? defaultVal : prop.getProperty(key);
	}

}

java 获取properties配置文件属性值

原文:http://blog.csdn.net/without0815/article/details/44569153

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!