/** 配置文件读取类 */
public class Properties extends Hashtable {
private static Properties self = new Properties();
public static Properties getInstance() {
return self;
}
public Properties() {
}
public void load(String name) {
InputStream is = self.getClass().getResourceAsStream(name);
if (is != null) {
read(is);
}
}
/** 文件读取方法 */
private void read(InputStream in) {
char word_uni_b_e[] = new char[1024];
String str = "";
DataInputStream dis = new DataInputStream(in);
int counter = 0;
char temp;
try {
dis.skip(2);
while (true) {
while (true) {
temp = dis.readChar();
if (temp == '/n') {
break;
} else {
word_uni_b_e[counter++] = temp;
}
}
str = String.valueOf(word_uni_b_e, 0, counter);
int index = str.indexOf('=');
if (index != -1)
put(str.substring(0, index), str.substring(index + 1, str.length() - 1));
str = "";
counter = 0;
word_uni_b_e = new char[1024];
}
} catch (IOException e) {
if (dis != null)
dis = null;
} finally {
if (dis != null)
dis = null;
}
}
/** 返回一个String 变量 */
public String readString(String msg) {
return (String) Properties.this.get(msg);
}
/** 返回一个int型变量 */
public int readInt(String msg) {
return Integer.parseInt((String) Properties.this.get(msg));
}
/** 返回一个boolean型变量 */
public boolean readBoolean(String msg) {
String tt = (String) get(msg);
if (tt.equals("false") || tt.equals("0"))
return false;
else
return true;
}
/** 返回一个short型变量 */
public short readShort(String msg) {
return (short) readInt(msg);
}
/** 返回一个byte型变量 */
public byte readByte(String msg) {
return (byte) readInt(msg);
}
/** 返回一个long型变量 */
public long readLong(String msg) {
return Long.parseLong((String) Properties.this.get(msg));
}
/** 返回大小 */
public int Size() {
return Properties.this.size();
}
}