I am using this code for import shutdownscheduler.xml
file from my package but I am getting error:
public static Document handler() throws ParserConfigurationException, SAXException, IOException{
String s=xmlhandler.class.getResource("shutdownscheduler.xml").toString();
File newFile=new File(s);
DocumentBuilderFactory documentbuilderfactory=DocumentBuilderFactory.newInstance();
DocumentBuilder documentbuilder=documentbuilderfactory.newDocumentBuilder();
Document document=(Document)documentbuilder.parse(newFile);
document.getDocumentElement();
return document;
}
Exception in thread "main" java.io.FileNotFoundException:
C:\Users\Rohan Kandwal\Documents\NetBeansProjects\Shutdown
Scheduler\file:\C:\Users\Rohan%20Kandwal\Documents\NetBeansProjects\Shutdown%20Scheduler\build\classes\shutdown\scheduler\shutdownscheduler.xml
(The filename, directory name, or volume label syntax is incorrect)
If I give a direct path of the file then the import is working correctly. But this will result in an error once 1 create a jar file of the project and run it on other system. So I want a way to import file from my package only.
the correct path for the file is C:\Users\Rohan Kandwal\Documents\NetBeansProjects\Shutdown Scheduler\src\shutdown\scheduler\shutdownscheduler.xml