package com.bjhy.platform.open.front.util;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import org.springframework.stereotype.Component;
@Component
public class ReadProperties {
private static Properties properties = new Properties();
static{
File file = new File(System.getProperty("user.dir"), "config"+File.separator+"platform.properties");
if(file.exists()){
try{
properties.load(new FileInputStream(file));
}catch(Exception e){
e.printStackTrace();
System.err.println("platform.properties配置文件读取失败");
}
}
}
public String getString(String key, String defaultValue){
Object obj = properties.get(key);
return obj!=null?(String)obj:defaultValue;
}
public int getInteger(String key, Integer defaultValue){
Object obj = properties.get(key);
return obj!=null?Integer.parseInt(obj.toString()):defaultValue;
}
public float getFloat(String key, Float defaultValue){
Object obj = properties.get(key);
return obj!=null?Float.parseFloat(obj.toString()):defaultValue;
}
public double getDouble(String key, Double defaultValue){
Object obj = properties.get(key);
return obj!=null?Double.parseDouble(obj.toString()):defaultValue;
}
public boolean getBoolean(String key, boolean defaultValue){
Object obj = properties.get(key);
return obj!=null?Boolean.parseBoolean(obj.toString()):defaultValue;
}
}
java 读取Properties文件
最新推荐文章于 2019-07-31 09:56:15 发布