package Easis.Common;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class PropertiesHelper {
private String _PropertiesFilePath="";
private Properties _prop=new Properties();
private InputStream _fis;
/**
* @param filePath 这里是指放在classes下,如果有包的话,前面加包名即可。例:/com/web/db.properties
* */
public PropertiesHelper(String filePath){
this._PropertiesFilePath=filePath;
try{
_fis =PropertiesHelper.class.getClassLoader().getResourceAsStream(filePath);
_prop.load(_fis);
}
catch (Exception e){
e.printStackTrace();
}
}
public Properties getProperties(){
return _prop;
}
public String get(String key){
if(_prop.containsKey(key)==false){
return "";
}
else{
return _prop.getProperty(key);
}
}
public boolean set(String key,String value){
if(_prop.containsKey(key)==false){
_prop.put(key,value);
}
else{
_prop.setProperty(key,value);
}
return true;
}
public void closeFileStream(){
if(_fis!=null){
try{
_fis.close();}
catch (Exception e){
e.printStackTrace();
}
}
}
}