日期:2014-05-20 浏览次数:20797 次
public class MyXMLReader { public static void main(String args[]) { long lasting = 0l; try{ lasting =System.currentTimeMillis(); File f=new File("data_10k.xml"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(f); NodeList nl = doc.getElementsByTagName("VALUE"); for (int i=0;i < nl.getLength();i++){ System.out.println("车牌号码:" + doc.getElementsByTagName("NO").item(i) .getFirstChild().getNodeValue()); System.out.println("车主地址:" + doc.getElementsByTagName("ADDR").item(i) .getFirstChild().getNodeValue()); } }catch(Exception e){ e.printStackTrace(); } System.out.println(" 运行时间:"+(System.currentTimeMillis() - lasting)+ "毫秒"); } }
------解决方案--------------------
首先long lasting =System.currentTimeMillis();作用域在try里面,long lasting =System.currentTimeMillis(); 肯定访问不到,然后就是全角空格的原因,把它删掉