xom报错 Exception in thread "main" java.net.UnknownHostException: file
Exception in thread "main" java.net.UnknownHostException: file at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.Socket.connect(Socket.java:579) at java.net.Socket.connect(Socket.java:528) at sun.net.ftp.impl.FtpClient.doConnect(FtpClient.java:958) at sun.net.ftp.impl.FtpClient.tryConnect(FtpClient.java:918) at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1013) at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:999) at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:294) at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:393) at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:613) at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648) at nu.xom.Builder.build(Unknown Source) at nu.xom.Builder.build(Unknown Source) at xml2.XOM.main(XOM.java:26)
package xml2; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import nu.xom.Builder; import org.xml.sax.XMLReader; public class XOM { public static void main(String[] args) throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(true); SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); reader.setErrorHandler(new SimpleErrorHandler()); Builder builder = new Builder(reader); builder.build("contacts.xml"); } }
为什么会报这个错误呢?我用的是xom-1.2.10.jar
package xml2; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import nu.xom.Builder; import org.xml.sax.XMLReader; public class XOM { public static void main(String[] args) throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(true); SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); reader.setErrorHandler(new SimpleErrorHandler()); Builder builder = new Builder(reader); builder.build("file:\\H:\\mycodes\\java\\jbpm\\xml2\\contacts.xml"); } }
从xom-1.2.10.jar开始使用file协议,挺不方便的