I am trying to create an XML file in Java and I pass the name of the file to the function argument, but I get the error: " The system cannot find the file specified". Does anyone have any idea about this error solution? My code is like:
static Document loadDocument(String fileName) { File inputFile = new File(fileName); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = null; try { docBuilder = docFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); } Document doc = null; try { doc = docBuilder != null ? docBuilder.parse(inputFile) : null; } catch (SAXException | IOException e) { e.printStackTrace(); } return doc; }
No comments:
Post a Comment