?? configparser.java
字號(hào):
package find;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
import java.util.Properties;
//使用DefaultHandler的好處 是 不必陳列出所有方法,
public class ConfigParser extends DefaultHandler {
////定義一個(gè)Properties 用來(lái)存放 dbhost dbuser dbpassword的值
private Properties props;
private String currentSet;
private String currentName;
private StringBuffer currentValue = new StringBuffer();
//構(gòu)建器初始化props
public ConfigParser() {
this.props = new Properties();
}
public Properties getProps() {
return this.props;
}
//定義開(kāi)始解析元素的方法. 這里是將<xxx>中的名稱xxx提取出來(lái).
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
currentValue.delete(0, currentValue.length());
this.currentName =qName;
}
//這里是將<xxx></xxx>之間的值加入到currentValue
public void characters(char[] ch, int start, int length) throws SAXException {
currentValue.append(ch, start, length);
}
//在遇到</xxx>結(jié)束后,將之前的名稱和值一一對(duì)應(yīng)保存在props中
public void endElement(String uri, String localName, String qName) throws SAXException {
props.put(qName.toLowerCase(), currentValue.toString().trim());
//System.out.println(props.toString());
//props.list(System.out);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -