package com.hxkj.fsslr.core.utils;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PropertiesUtils {
private static Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);
private static final String CONFIG_FILE_PATH = "config.properties";
private static Properties prop = new Properties();
static{
reflushProperties(CONFIG_FILE_PATH);
}
public static void reflushProperties(String configFileName){
String path = "";
if(configFileName != null && configFileName.trim() != ""){
path = PropertiesUtils.class.getClassLoader().getResource(configFileName).getPath();
}else{
path = PropertiesUtils.class.getClassLoader().getResource("config.properties").getPath();
}
try{
FileInputStream in = new FileInputStream(path);
prop.load(in);
in.close();
}catch(Exception e){
e.printStackTrace();
}
}
public static String getPropertiesValue(String propertiesName){
return prop.getProperty(propertiesName);
}
public static boolean setPropertiesValue(String propertiesName,String propertiesValue){
boolean result = false;
String path = PropertiesUtils.class.getClassLoader().getResource(CONFIG_FILE_PATH).getPath();
try {
FileOutputStream out = new FileOutputStream(path);
prop.setProperty(propertiesName, propertiesValue);
prop.store(out, "update CUID_PRE");
out.close();
result = true;
} catch (Exception e) {
e.printStackTrace();
logger.error("FSSLR-WEBSERVER-ERROR:config.properties写入失败");
}
return result;
}
}