I have a piece of code that is meant to update an xml file that is inside the package and in a resource folder (This is a standalone desktop project). This code runs well in the IDE when I include the path to the src folder eg
File file = new File("src/tools/con.xml");
My problem is that this doesn't work outside of the IDE for example in a deployed application because the resource is bundled into a jar. I have tried using classloader methods getResource/getResourceAsStream() but without success e.g.
File file = new File(getClass().getResource("/tools/con.xml").toString() );
Below is my full code
try{
File file = new File("src/tools/con.xml");
StreamResult result = new StreamResult(file);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
DOMSource source = new DOMSource(doc);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(source, result);
}catch (IllegalArgumentException | TransformerException e) {
throw new IOException("Failed to save the doc");
}