读配置文件property文件



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

import org.springframework.core.io.support.PropertiesLoaderUtils;

/**
* Description: 读取配置文件http地址配置<br>
*/
public class ConfigFileUtils {

/**
* 读取authconfig.properties
*
* @param nodeName
* @return
*/
public static String getAuthconfig(String nodeName) {
String configName = "application.properties";
String result = pubReadConfig(configName, nodeName);
if (result == null) {
result = pubReadConfig("prop/" + configName, nodeName);
}
return result;
}

/**
* 通用读取方法
*
* @param configName
* @param nodeName
* @return
*/
public static String pubReadConfig(String configName, String nodeName) {
Properties props = new Properties();
while (true) {
try {
props = PropertiesLoaderUtils.loadAllProperties(configName);
return (String) props.get(nodeName);
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
}
posted @ 2017-09-27 14:08  雄狮_杜  阅读(711)  评论(0编辑  收藏  举报