java读取XML文件
1.读取XML文件的类:
public class XMLUtils {
private final String DB_XML_FILE = "/XMLSetting.xml";
public Properties getPropertiesfromXML() {
URL url = XMLUtils.class.getResource(dBXMLFILE);
URI uri;
try {
uri = url.toURI();
InputSource xmlfile = new InputSource(uri.getPath());
MyDefaultHandler handler = new MyDefaultHandler ();
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser parser = parserFactory.newSAXParser();
parser.parse(xmlfile, handler);
return handler.getProps();
} catch (ParserConfigurationException e) {
System.out.println(e.getMessage());
return null;
} catch (SAXException e) {
System.out.println(e.getMessage());
return null;
} catch (IOException e) {
System.out.println(e.getMessage());
return null;
} catch (URISyntaxException e) {
System.out.println(e.getMessage());
return null;
}
}
}
2.处理XML文件的类:
import java.util.Properties;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import com.app.common.Constants;
public class MyDefaultHandler extends DefaultHandler {
private Properties props;
private String key = "";
private StringBuffer value = new StringBuffer();
public MyDefaultHandler() {
props = new Properties();
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
value.append(ch, start, length);
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
props.put(key, value.toString().trim());
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
value.delete(0, value.length());
key = attributes.getValue(Constants.KEY);
}
public Properties getProps() {
return this.props;
}
}
3.main:
import java.util.Properties;
pu
相关文档:
//** **********创建工作簿************ */
WritableWorkbook workbook = Workbook.createWorkbook(new File("d:/test.xls"));
/** *//** **********创建工 ......
NVelocity是Java模板引擎Velocity的.Net版本。NVelocity目前官方版本为0.42。官方地址:http://nvelocity.sourceforge.net/,原作者已经申明不再对NVelocity做技术支持了,所以sourceforge上NVelocity版本一直是0.42不再有更新了。不过目前NVelocity已经有1.0的版本了,是由castleproject项目维护的。NVelocity.dll能在cast ......
1、http://java.sun.com/
(英文)
Sun的Java网站,是一个应该经常去看的地方。不用多说。
2、http://www-900.ibm.com/developerWorks/cn/
IBM的developerWorks网站,英语好的直接去英文主站点看。这里不但是一个极好的面向对象的分析设计网站,也是WebServices,Java,Linux极好的网站。强烈推荐!!!
3、http://www.j ......
package cn.eshore.mismp.sms.ws.send;
public class Base64 {
/**
* 将原始数据编码为base64编码
*/
static public char[] encode(byte[] data) {
char[] out = new char[((data.length + 2) / 3) * 4];
for (int i = 0, index = 0; i < data.length; i += 3, index += 4) {
boolean quad = false ......
在JDK1.5之前,对高质量Java多线程并发程序设计时,为防止程序崩掉等现象的出现,比如使用wait()、notify()和synchronized等,需要考虑性能、死锁、公平性、资源管理以及如何避免线程安全性方面带来的危害等诸多因素,通常会采用一些较为复杂的安全策略,加重了程序员的开发负担。在J ......