简体   繁体   English

SAXParser 为 XML 文件提供 FileNotFoundException

[英]SAXParser gives FileNotFoundException for XML file

My Java application gives a FileNotFoundException when trying to parse an XML file with the SAXParser class. The stack trace is:我的 Java 应用程序在尝试使用 SAXParser class 解析 XML 文件时给出了 FileNotFoundException。堆栈跟踪是:

    java.base/java.io.FileInputStream.open0(Native Method),
    java.base/java.io.FileInputStream.open(Unknown Source), 
    java.base/java.io.FileInputStream.<init>(Unknown Source), 
    java.base/java.io.FileInputStream.<init>(Unknown Source), 
    java.base/sun.net.www.protocol.file.FileURLConnection.connect(Unknown  Source), 
    java.base/sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source),  
    java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown  Source), 
    java.xml/com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown   Source), 
    java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown  Source), 
    java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown   Source), 
    java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source),  
    java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source),  
    java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source), 
    java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source),  
    java.xml/javax.xml.parsers.SAXParser.parse(Unknown Source)

I ran the application on Windows and on Linux, on Linux I can reproduce it more frequently (I don't know why...).我在 Windows 和 Linux 上运行应用程序,在 Linux 上我可以更频繁地重现它(我不知道为什么......)。 The problem appears to occur randomly and I am sure the file exists and can be read.该问题似乎是随机发生的,我确定该文件存在并且可以读取。

  • JRE release details: JRE 发布细节:
    IMPLEMENTOR="Eclipse Adoptium"
    IMPLEMENTOR_VERSION="Temurin-17.0.2+8"
    JAVA_VERSION="17.0.2"
    JAVA_VERSION_DATE="2022-01-18"
  • I checked and removed any redundant SAXParser classes from the classpath.我检查并从类路径中删除了所有多余的 SAXParser 类。
  • I tried different folders as the file source folder (local, samba share).我尝试了不同的文件夹作为文件源文件夹(本地、samba 共享)。
  • I tried with file permissions set to 777.我尝试将文件权限设置为 777。

This link suggests it may be an issue related to permissions: https://community.cloudera.com/t5/Support-Questions/CDF-Add-NiFi-CA-Service-Service-to-Cluster/mp/268975/highlight/true此链接表明这可能是与权限相关的问题: https://community.cloudera.com/t5/Support-Questions/CDF-Add-NiFi-CA-Service-Service-to-Cluster/mp/268975/highlight/真的

But that does not work for me.但这对我不起作用。

EDIT: I have pasted the XML file contents here: https://pastebin.com/Q0WE9Y9S编辑:我在这里粘贴了 XML 文件内容: https://pastebin.com/Q0WE9Y9S

EDIT: I have configured the SAXParserFactory so it does not load external DTD's:编辑:我已经配置了 SAXParserFactory,因此它不会加载外部 DTD:

    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = factory.newSAXParser();
    factory.setValidating(false);
    factory.setNamespaceAware(false);
    factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

I have resolved this issue, it was due to another bug in my own code.我已经解决了这个问题,这是由于我自己的代码中的另一个错误。 So it had nothing to do with the SAXParser.所以它与 SAXParser 无关。 Thanks for all the help!感谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM