读取文本、配置文件

/** 配置文件读取类 */

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();

}

 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值