获取配置文件

//配置文件

company.name=Neusoft
company.copyright.display=true
company.item= http\://www.neusoft.com/cn/0267/index.html
company.item.display=true
company.aboutUs=http\://platform.neusoft.com
company.aboutUs.display=true
company.privacy=http\://www.neusoft.com/cn/0266/index.html
company.privacy.display=true
product.name=SaCa Aclome
company.login = \u767B\u5F55 Aclome
company.register = \u6CE8\u518C Aclome
company.title = Aclome Business Center

//java

package com.neusoft.aclome.core.util;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 
 * 
 * 
 */
public class CompanyConfigureUtil {
	
	private static final String description = "Theme configration, aboutUS e.g http://www.exapmle.com";
	
	public enum PropertyKey{
		aboutUs("company.aboutUs"),
		aboutUsDisplay("company.aboutUs.display"),

		privacy("company.privacy"),
		privacyDisplay("company.privacy.display"),
		
		item("company.item"),
		itemDisplay("company.item.display"),
		
		copyrightDisplay("company.copyright.display"),
		copyrightCompanyName("company.name"),
		
		productName("product.name");
		
		String key;
		private PropertyKey(String key) {
			this.key = key;
		}
		
		public String toString(){
			return this.key;
		}
		
		public String getKey(){
			return this.key;
		}
	}
	
	
	private static final Log log = LogFactory.getLog(ConfigureUtil.class);
	private static Properties prop = new Properties();
	static {
		InputStream in =null;
		try {
			in = ConfigureUtil.class.getResourceAsStream("/companyConfig.properties");
			prop.load(in);
		} catch (IOException e) {
			log.error("load companyConfig.properties failed.", e);
		}finally {
            if (in != null) {
                try {
                    in.close();
                    in = null;
                } catch (IOException e) {
                }
            }
        }
	}

	public static String getString(String key) {
		return prop.getProperty(key, "");
	}

	public static int getInt(String key) {
		String value = prop.getProperty(key, "0");
		return Integer.valueOf(value).intValue();
	}

	public static boolean getBoolean(String key) {
		String value = prop.getProperty(key, "false");
		if (value.equalsIgnoreCase("true") || value.equals("1")) {
			return true;
		} else {
			return false;
		}
	}
	public static void setKeyAndValue(String key , String value){
		prop.setProperty(key, value);
	}
	
	public static void storePropertyToFile() throws Exception {
		String propPath = ConfigureUtil.class.getResource("/").getPath() + "/companyConfig.properties";
		OutputStream fos = new FileOutputStream(propPath);
		try {
			prop.store(fos, description);
			fos.close();
		} catch (Exception e) {
			log.error("Close outpustream failed.", e);
		} finally {
			if (fos != null) {
				try {
					fos.close();
				} catch (Exception e) {
				}
			}
		}
	}
}

//引用

String copyrightCompanyName = CompanyConfigureUtil.getString(CompanyConfigureUtil.PropertyKey.copyrightCompanyName.getKey());
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值