欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

创建系统参数 (实例化参数)

程序员文章站 2022-05-10 08:45:59
...
参数文件
[quote]qnr.properties 之中属性:exportURL=http://ww...[/quote]


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class SystemProperties {

private Properties qnrSystemProperties = new Properties();
private static SystemProperties context = null ;

private SystemProperties() {

}
private void init(){
initQnr();
}


private void initQnr() {
String path = this.getClass().getResource("/").getPath()
+ "qnr.properties";

FileInputStream fin = null;
try {
fin = new FileInputStream(path);
qnrSystemProperties.load(fin);
fin.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
return;
} catch (IOException e) {
e.printStackTrace();
return;
}

}
public synchronized static SystemProperties getSystemPropertie()
{
if(context == null)
{
context = new SystemProperties();
context.init();
}
return context;
}

public String getQnrPropertyValue(String property){

return qnrSystemProperties.getProperty(property);
}

}


[quote]
String updateURL = SystemProperties.getSystemPropertie()
.getQnrPropertyValue("exportURL");
[/quote]
相关标签: properties