📄 propertyreader.java
字号:
package zsw_mmorpg.log;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Digital Online</p>
* @author byron.peng
* @version 1.0
*/
import java.io.*;
import java.util.*;
public class propertyreader {
private boolean isValid = true;
private Hashtable properties;
private String fileProperties = "doappserver.property"; //配置文件
public propertyreader(String filename) {
this.fileProperties = filename;
init(); //初始属性
}
/**
* 初始属性
*/
private void init() {
properties = new Hashtable();
try {
Properties temp = loadProps(fileProperties);
Enumeration e = temp.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = (String) temp.get(key);
value = gbToUnicode(value);
properties.put(key, value);
}
}
catch (Exception e) {
e.printStackTrace();
isValid = false;
}
catch (Throwable t) {
isValid = false;
}
}
/**
* 打开属性文件
*/
private Properties loadProps(String propname) {
Properties temp = new Properties();
try {
try {
File readFile = new File(propname);
FileInputStream fis = new FileInputStream(readFile);
temp.load(fis);
fis.close();
}
catch (FileNotFoundException e) {
Loger.error("File Not Found:" + propname, e);
}
}
catch (IOException e) {}
return temp;
}
/**
* 给出属性内容
*/
public Hashtable get() {
return properties;
}
/**
* 取属性值
*/
public String getString(String str) {
Enumeration e = properties.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
if (key.equals(str)) {
return (String) properties.get(key);
}
}
return "";
}
/**
* 重新读取属性
*/
public void reInit() {
init();
}
/**
* 取属性字串值
*/
public String getString(String str, String value) {
Enumeration e = properties.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
if (key.equals(str)) {
return (String) properties.get(key);
}
}
return value;
}
/**
* 取整数据属性值
*/
public int getInt(String str) {
String s = getString(str);
int i = Integer.parseInt(s);
return i;
}
public int getInt(String str, int value) {
String s = getString(str);
int i = value;
if (s != null && s.trim().length() != 0) {
i = Integer.parseInt(s);
}
return i;
}
/**
* 取长整型数据
*/
public long getLong(String name, long defaultValue) {
long value = defaultValue;
try {
String object = getString(name);
if (object != null) {
value = Long.valueOf(object).longValue();
}
}
catch (NumberFormatException exception) {
}
return value;
}
/**
* 将 GB 转成 UNICODE
*/
public String gbToUnicode(String gbString) {
if (gbString == null || gbString.length() == 0) {
return "";
}
String uniMessage;
try {
char buffer_ch[] = gbString.toCharArray();
byte cb[] = new byte[buffer_ch.length];
for (int n = 0; n < buffer_ch.length; n++) {
cb[n] = (byte) buffer_ch[n];
}
uniMessage = new String(cb, "GB2312");
}
catch (UnsupportedEncodingException e) {
uniMessage = "";
}
return uniMessage;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -