title: Connecting to XML file from jar file
body: <p>Where can I put XML file to enable the program to access it even when I generate the jar file for it?</p>
  
  <p>When I put the XML file in the project file the program successfully run as the following code: </p>
  
  <pre><code>public class one {
  
      public final static void main(String[] args) throws Exception {
  
        FileInputStream file = new java.io.FileInputStream("document.xml");//i put document.xml in project file
        javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
        dbf.setCoalescing(true);
        javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
        org.w3c.dom.Document doc = db.parse(file);
  
        one obj = new one ();
        obj.changeValue(doc, "192837465", "192837465");
        obj.save("document.xml",doc);
      }
  
      public void changeValue(org.w3c.dom.Document doc, String oldValue, String NewValue) throws Exception{
        org.w3c.dom.Element root = doc.getDocumentElement();
        org.w3c.dom.NodeList childNodes = root.getElementsByTagName("Employee");
        for (int i = 0; i &lt; childNodes.getLength(); i++) {
          org.w3c.dom.NodeList subChildNodes = childNodes.item(i).getChildNodes();
          for (int j = 0; j &lt; subChildNodes.getLength(); j++) {
            try {
               if (subChildNodes.item(j).getTextContent().equals(oldValue)) {
                  subChildNodes.item(j).setTextContent(NewValue);
               }
            } catch (Exception e) {
                e.printStackTrace();
            }
          }
        }
      }
  
      public void save(String url ,org.w3c.dom.Document doc) throws Exception {
  
          javax.xml.transform.TransformerFactory factory1 = javax.xml.transform.TransformerFactory.newInstance();
          javax.xml.transform.Transformer transformer = factory1.newTransformer();
          transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes");
          java.io.StringWriter writer = new java.io.StringWriter();
          javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(writer);
          javax.xml.transform.dom.DOMSource source = new javax.xml.transform.dom.DOMSource(doc);
          transformer.transform(source, result);
          String s = writer.toString();
          System.out.println(s);
  
          java.io.FileWriter fileWriter = new java.io.FileWriter(url);
          java.io.BufferedWriter bufferedWriter = new java.io.BufferedWriter(fileWriter);
  
          bufferedWriter.write(s);
  
          bufferedWriter.flush();
          bufferedWriter.close();
      }
  }
  </code></pre>
  
  <p>but when I make the program in jar file using eclipse and run the file from command prompt using this command:</p>
  
  <pre><code>java -jar xml.jar
  </code></pre>
  
  <p>it gives me this exception:</p>
  
  <pre><code>Exception in thread "main" java.io.FileNotFoundException: document.xml (The system cannot find the file specified)
          at java.io.FileInputStream.open(Native Method)
          at java.io.FileInputStream.&lt;init&gt;(Unknown Source)
          at java.io.FileInputStream.&lt;init&gt;(Unknown Source)
          at one.main(one.java:13)
  </code></pre>
  
  <p>Why this error and how to correct it?</p>