今天迁移邮件管理功能的时候,有个图片上传功能,有个访问路径是在resources.properties配置,这个项目没有配置就找不到了。
正好发现了这个问题,就把读取resource配置文件的方法提供给大家。
package com.bonatone.knowledge.util;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ResourcesUtil {
public static String getProperties(String name){
Properties props = getPropertiesInCache();
String value = props.getProperty(name);
return value;
}
public static Properties getPropertiesInCache() throws SecurityException {
Properties pro = null;
if(pro == null){
pro = getProperties();
}
return pro;
}
private static Properties getProperties(){
try {
InputStream in = Thread.currentThread().getContextClassLoader().getResource("resources.properties").openStream();
Properties props = new Properties();