配置文件加载工具类

来源:互联网 发布:淘宝首页流量 编辑:程序博客网 时间:2024/05/22 13:41

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

public class PropertyTool {

private Properties property = new Properties();

public static PropertyTool getInstance(String fileName) {
PropertyTool temp = new PropertyTool();
if (!temp.load(new File(fileName)))
return null;
return temp;
}

private boolean load(File file) {
if (file == null)
return false;

if (!file.exists())
return false;

FileInputStream fin;
try {
fin = new FileInputStream(file);
property.load(fin);
} catch (Exception e) {
return false;
}
return true;
}

public String getProperty(String key) {
if (key == null)
return null;

return property.getProperty(key);
}
}



原创粉丝点击