📄 rcloader.java
字号:
package com.ismyway.util;
import java.io.InputStream;
import java.util.Hashtable;
public class RcLoader {
private Hashtable bundle = null;
public RcLoader(String path) {
if (null != path) {
load(path);
}
}
private void load(String path) {
try {
InputStream is = new Object().getClass().getResourceAsStream(path);
byte[] buf = new byte[is.available()];
is.read(buf);
is.close();
bundle = parseResource(new String(buf, "UTF-8"));
} catch (Exception e) {
//e.printStackTrace();
}
}
public String get(String key) {
String res = null;
if (bundle != null) {
res = (String) bundle.get(key);
if (res != null) {
return res;
}
}
return key;
}
private Hashtable parseResource(String r) throws Exception {
Hashtable res = new Hashtable();
int idx = 0, next;
int lidx;
String line = null, key, val;
try {
while ((next = r.indexOf("\n", idx)) > -1) {
line = r.substring(idx, next).trim();
idx = next + 1;
if (line.length() == 0 || line.charAt(0) == '#')
continue;
lidx = line.indexOf("=");
if (lidx == -1) {
continue;
}
key = line.substring(0, lidx).trim();
val = line.substring(lidx + 1).trim();
res.put(key, val);
}
//最后一行
line = r.substring(idx).trim();
if (line.length() > 0 && line.charAt(0) != '#') {
lidx = line.indexOf("=");
if (lidx > -1) {
key = line.substring(0, lidx).trim();
val = line.substring(lidx + 1).trim();
res.put(key, val);
}
}
} catch (Exception e) {
throw new Exception(e.toString() + "\n" + line);
}
return res;
}
public void clear() {
if (null != bundle) {
bundle.clear();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -