import java.io.IOException;
import java.io.InputStream;
import java.sql.Clob;
import java.sql.SQLException;
import java.util.Properties;
/**
*
* 配置初始化类
*
* @version
*
*/
public class PropertiesUtil {
/**
* @param key
* @return
*/
public String loadProperties(String key) {
Properties properties = new Properties();
InputStream stream = Thread.currentThread().getContextClassLoader()
.getResourceAsStream("property.properties");
try {
properties.load(stream);
} catch (IOException e) {
e.printStackTrace();
}
return properties.getProperty(key);
}
public String getProperties(String key, Clob info) {
Properties properties = new Properties();
InputStream is;
try {
is = info.getAsciiStream();
properties.load(is);
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return properties.get(key).toString();
}
}
/**
*
*
* 读取配置后将数据信息写入到 本地配置中
*
* @version
*
*/
public class ConfigInit {
public static String configInit(String configName) {
return new PropertiesUtil().loadProperties(configName);
}
public static String configInit(String key, Clob content) {
String config = new PropertiesUtil().getProperties(key, content);
return config;
}
}
可以直接读取resources下的内容: