import java.io.IOException;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.support.PropertiesLoaderUtils;
public class PropertiesUtil {
private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
private static Properties properties= new Properties();
/*properties文件名*/
private static final String PROPERTIES_FILE_NAME="centrin-dao.properties";
public static String getProperty(String name) {
String result = null;
try {
//下载文件
properties = PropertiesLoaderUtils.loadAllProperties(PROPERTIES_FILE_NAME);
result = properties.getProperty(name);//根据name得到对应的value
} catch (IOException e) {
logger.warn(" loadAllProperties error 1");
e.printStackTrace();
}
return result;
}
public static String getProperty(String name ,String properties_name) {
String result = null;
try {
//下载文件
properties = PropertiesLoaderUtils.loadAllProperties(properties_name);
result = properties.getProperty(name);//根据name得到对应的value
} catch (IOException e) {
logger.warn(" loadAllProperties error 1");
e.printStackTrace();
}
return result;
}
public static void main(String[] args) throws IOException {
System.out.println(PropertiesUtil.getProperty("createPlanPath"));
}
}
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.support.PropertiesLoaderUtils;
public class PropertiesUtil {
private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
private static Properties properties= new Properties();
/*properties文件名*/
private static final String PROPERTIES_FILE_NAME="centrin-dao.properties";
public static String getProperty(String name) {
String result = null;
try {
//下载文件
properties = PropertiesLoaderUtils.loadAllProperties(PROPERTIES_FILE_NAME);
result = properties.getProperty(name);//根据name得到对应的value
} catch (IOException e) {
logger.warn(" loadAllProperties error 1");
e.printStackTrace();
}
return result;
}
public static String getProperty(String name ,String properties_name) {
String result = null;
try {
//下载文件
properties = PropertiesLoaderUtils.loadAllProperties(properties_name);
result = properties.getProperty(name);//根据name得到对应的value
} catch (IOException e) {
logger.warn(" loadAllProperties error 1");
e.printStackTrace();
}
return result;
}
public static void main(String[] args) throws IOException {
System.out.println(PropertiesUtil.getProperty("createPlanPath"));
}
}