I have an XML file I want to parse and the parser I am using takes java.io.File. The XML file itself needs to be within the jar file and I have it in a folder called resources. The class I'm calling it from is in a package called test so I'm using ../ to go up a package first being going into the resources folder/package where the file is located. The below code successfully works when I debug it within Netbeans however when I deploy this as a jar file the input stream ends up being null. I extracted the content of the jar file and it does indeed have the XML file correctly located in resources folder so it is there but the below code doesnt find it I guess. Any ideas?
package test; private void myMethod() { InputStream inputStream = MyClass.class.getResourceAsStream("../resources/file.xml"); File file = File.createTempFile("tmp", "tmp"); try (OutputStream outputStream = new FileOutputStream(file)) { int read = 0; byte[] bytes = new byte[1024]; while ((read = inputStream.read(bytes)) != -1) { outputStream.write(bytes, 0, read); } } }