This is my code.
File file = new File("src/qrcodescanner/xmlpac/"+filename);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
document = db.parse(file);
document.getDocumentElement().normalize();
If it can’t be red it most probably isn’t where you expect it to be. Judging by the code you posted I suppose that your xml file is intended to reside inside your jar/package structure.
This is my test project structure:
The corresponding generated jar file is located at
target/directory and looks like this:MyResource.xmllooks like this:MyCode.javalooks like this:When run it prints:
Method getResourceAsStream is used for loading resources from inside the JAR. Hope that helps.