String xmlFileName ="file:D:\ps\a.xml";  
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(xmlFileName);
xmlRoot = doc.getRootElement();为什么要加这个file: 如果不加则会报错:java.net.MalformedURL Exception: unknown protocol: d

解决方案 »

  1.   

        /**
         * <p>
         * This builds a document from the supplied
         *   URI.
         * </p>
         * @param systemId URI for the input
         * @return <code>Document</code> resultant Document object
         * @throws JDOMException when errors occur in parsing
         * @throws IOException when an I/O error prevents a document
         *         from being fully parsed
         */
        public Document build(String systemId)
    SAXBuilder sb = new SAXBuilder(); 
    Document doc = sb.build(new File("D:\\ps\\a.xml"));