Hello!
I have a program that is a XML-parser, and it works fine when I'm running it from NetBeans. But when I create a JAR-file and run the very same program, it cannot find the xml file. Consider this small program that addresses my problem:
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class XMLTest { Document d; public XMLTest() throws ParserConfigurationException, FileNotFoundException, IOException, SAXException { String docString = "C:\\someXML.xml"; DocumentBuilderFactory dbf; dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(true); dbf.setIgnoringElementContentWhitespace(true); DocumentBuilder db = dbf.newDocumentBuilder(); InputStream in = new FileInputStream(docString); d = db.parse(in); } public static void main(String[] args) throws ParserConfigurationException, FileNotFoundException, IOException, SAXException { XMLTest t = new XMLTest(); } }
Hank