I have the following code to open up an XML file for parsing. My problem is with the variable designPath: it currently has to be a relative path from my program's root directory. However, when I pass an absolute path it doesn't work.
// Get the DOM Builder Factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Get the DOM Builder
DocumentBuilder builder = factory.newDocumentBuilder();
// Load and Parse the XML document
// document contains the complete XML as a Tree
Document document = builder.parse(ClassLoader.getSystemResourceAsStream(designPath));
How can I make this work with either an absolute or relative path in the designPath variable?
The issue is with the function ClassLoader.getSystemResourceAsStream that takes a "resource of the specified name from the search path used to load classes." according to Java docs but I want to be able to use it with an absolute path.
Note that my designPath may be on a different drive than my program.