import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesLoader {
public static Properties getProperties(String propertyFileName)
throws IOException {
InputStream is = null;
try{
String configPath = System.getProperty("configPath");
if((configPath!=null&&!configPath.trim().equals(""))){
is = new FileInputStream(new File(configPath+File.separator+propertyFileName));
}else{
is = PropertiesLoader.class.getResourceAsStream("filePath"+propertyFileName);
}
if(null==is){
throw new FileNotFoundException(configPath + File.separator + propertyFileName+" not found");
}
Properties props = new Properties();
props.load(is);
return props;
}
finally{
if(is!=null){
try{
is.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
}
}
属性文件加载工具类实现---PropertiesLoader
最新推荐文章于 2021-12-15 15:38:41 发布