创建系统参数 (实例化参数)
程序员文章站
2022-05-10 08:45:59
...
参数文件
[quote]qnr.properties 之中属性:exportURL=http://ww...[/quote]
[quote]
String updateURL = SystemProperties.getSystemPropertie()
.getQnrPropertyValue("exportURL");
[/quote]
[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]
上一篇: PHP中获取文件路径信息
下一篇: 正斜杠(“/“)和反斜杠(“\“)的用法