public class PropertiesFile {
private Properties prop ;
public PropertiesFile()
{
prop = new Properties();
}
public PropertiesFile(String filePath,String propertiesName)
{
prop = new Properties();
try{
FileInputStream inputFile = new FileInputStream(filePath+propertiesName);
prop.load(inputFile);
inputFile.close();
} catch (FileNotFoundException ex){
System.out.println("读取属性文件失败,文件路径错误或者文件不存在");
ex.printStackTrace();
} catch (IOException ex) {
System.out.println("装载文件失败!");
ex.printStackTrace();
}
}
public PropertiesFile(String propertiesName)
{
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propertiesName);
prop = new Properties();
try {
prop.load(inputStream);
inputStream.close();
}catch (FileNotFoundException ex){
System.out.println("读取属性文件失败,文件路径错误或者文件不存在");
ex.printStackTrace();
} catch (IOException ex) {
System.out.println("装载文件失败!");
ex.printStackTrace();
}
}
public String getValue(String key)
{
if(prop.containsKey(key))
{
String value = prop.getProperty(key);
return value ;
}else{
return "";
}
}
}