📄 global.java
字号:
package msg;
import java.io.*;
import java.sql.*;
import java.util.*;
public class Global{
static private Global instance=null;
static Hashtable variables=new Hashtable();
static int loadTimes=0;
static synchronized public Global getInstance() {
if(instance == null) {
instance = new Global();
}
return instance;
}
public void loadParas(){
try{
String path=(((getClass()).getResource("")).getPath()).toString();
path=path.substring(0,path.indexOf("WEB-INF"));
//读取域名参数
InputStream is = new FileInputStream(path+"config/domain");//
Properties props = new Properties();
try {
props.load(is);
is.close();
}
catch (Exception e) {
try{is.close(); }catch(Exception ee){}
}
Iterator it=props.entrySet().iterator();
while(it.hasNext()){
Map.Entry entry=(Map.Entry)it.next();
Object key = entry.getKey();
Object value = entry.getValue();
variables.put(key,value);
}
//读取其他全局参数
is = new FileInputStream(path+"config/globalPara");//
props = new Properties();
try {
props.load(is);
is.close();
}
catch (Exception e) {
try{is.close(); }catch(Exception ee){}
}
it=props.entrySet().iterator();
while(it.hasNext()){
Map.Entry entry=(Map.Entry)it.next();
Object key = entry.getKey();
Object value = entry.getValue();
variables.put(key,value);
}
}catch(Exception ee){}
loadTimes++;
}
static public String getParameter(String para){
if(loadTimes==0)
Global.getInstance().loadParas();
return (String)variables.get(para);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -