未知协议:c(JDOM 和 SAXBuilder)

发布于 2024-12-02 06:03:20 字数 1165 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吾家有女初长成 2024-12-09 06:03:20

我的第一个猜测是您正在加载本地文件,例如:“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:// or file://

Try file://c:/mylocalfile.xml

ぽ尐不点ル 2024-12-09 06:03:20

实际上,我的文件夹名称中有空格导致了此错误。即使对于本地文件,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.

请恋爱 2024-12-09 06:03:20

我的文件名中有一个空格,

我使用 InputStream 而不是文件名解决了它:

works:

fis = new FileInputStream(filename);
Document doc = new SAXBuilder().build(fis);

crashes:

Document doc = new SAXBuilder().build(filename);

I had a space in my file name

i solved it using an InputStream instead of the filename:

works:

fis = new FileInputStream(filename);
Document doc = new SAXBuilder().build(fis);

crashes:

Document doc = new SAXBuilder().build(filename);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文