未知协议:c(JDOM 和 SAXBuilder)
我正在使用 JDOM 和 SAXBuilder 来解析 XML 文件,并且我遇到了一个抛出此错误的文件问题:
java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(URL.java:574)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:518)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:986)
at com.foo.moo.MyClass.getValues(MyClass.java:321)
行是:
Document document = null;
document = sxb.build(files.elementAt(i)); // This one
在互联网上做了一些研究后,我认为该错误与 Java 1.6 有关。
你怎么认为 ?
I'm using JDOM with SAXBuilder to parse XML files, and I have a problem with a file which is throwing this error :
java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(URL.java:574)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:518)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:986)
at com.foo.moo.MyClass.getValues(MyClass.java:321)
And the line is :
Document document = null;
document = sxb.build(files.elementAt(i)); // This one
After doing some research on the internet, I think the error is related to Java 1.6.
What do you think ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的第一个猜测是您正在加载本地文件,例如:“c:/mylocalfile.xml”,
但是此 URL 不包含协议,例如
http://
、ftp:// /
或file://
尝试 file://c:/mylocalfile.xml
My first guess is that you are loading a local file, like: "c:/mylocalfile.xml"
But this URL does not contain the protocol, like
http://
,ftp://
orfile://
Try file://c:/mylocalfile.xml
实际上,我的文件夹名称中有空格导致了此错误。即使对于本地文件,JAVA 也有能力理解协议类型。
Actually, I had space in my folder name which caused this error. Even in case of local files JAVA has the capability of understanding the protocol types.
我的文件名中有一个空格,
我使用 InputStream 而不是文件名解决了它:
works:
crashes:
I had a space in my file name
i solved it using an InputStream instead of the filename:
works:
crashes: