config.java
来自「考勤管理系统是针对学校每个月的考勤的报表进行总结」· Java 代码 · 共 86 行
JAVA
86 行
package setting;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Properties;
import action.Log;
public class Config {
private Properties props = null;
private String confFile = "";
public Properties loadProp(String confFile) throws IOException {
this.confFile = confFile;
InputStream is = getClass().getResourceAsStream(confFile);
this.props = new Properties();
props.load(is);
is.close();
return props;
}
public String getParam(String par)
throws UnsupportedEncodingException {
String parValue = this.props.getProperty(par);
parValue = URLDecoder.decode(parValue, "UTF-8");
return parValue;
}
public void setParam(String key, String par)
throws UnsupportedEncodingException {
par = URLEncoder.encode(par, "UTF-8").replace("\\", "\\\\");
this.props.setProperty(key, par);
}
public void savaProp() throws IOException, URISyntaxException {
File file = new File(getClass().getResource(this.confFile).toURI());
OutputStream out = new FileOutputStream(file);
this.props.store(out, this.confFile);
}
public String getCopyright() {
try {
return this.getParam("copyright");
} catch (UnsupportedEncodingException e) {
Log.writeLog("settion.Config.getCopyriht:\n\t读取版权设置时出错!");
return "五邑大学";
}
}
public String getContact() {
try {
return this.getParam("contact");
} catch (UnsupportedEncodingException e) {
Log.writeLog("settion.Config.getCopyriht:\n\t读取联系方式设置时出错!");
return "五邑大学";
}
}
public String getProp(String prop, String valu) {
InputStream is = getClass().getResourceAsStream(prop);
Properties props = new Properties();
try {
props.load(is);
is.close();
} catch (IOException e1) {
Log.writeLog("settion.Config.getCopyriht:\n\t读取参数"+valu+"时出错!");
return null;
}
String parValue = props.getProperty(valu);
try {
parValue = URLDecoder.decode(parValue, "UTF-8");
return parValue;
} catch (UnsupportedEncodingException e) {
Log.writeLog("settion.Config.getCopyriht:\n\t读取参数"+valu+"时出错!");
return null;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?