Programming
18 April 2012 0 Comments

Fixing SAXParser Error “The system cannot find the file specified” for DTD files

When parsing an XML file with the SAXParser class, you may run into an error related to a .dtd file that cannot be found.

Example: We are parsing the file D:\homologene\build65\homologene.xml.

The first lines of the XML are:

 version="1.0"?>

>
  >
    >
      >3>

We see a DOCTYPE declaration that points to a DTD file. DTD stands for Document Type Definition, and it is used to define the format of the XML file. The SAXParser will automatically look for this file in the same directory as the XML file.

When parsing we get the following error:

java.io.FileNotFoundException: D:\homologene\build65\HomoloGene.dtd (The system cannot find the file specified)
  at java.io.FileInputStream.open(Native Method)
  at java.io.FileInputStream.(Unknown Source)
  at java.io.FileInputStream.(Unknown Source)
  at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
  at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown