//配置文件
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());