我正在尝试用Java创建一个XML文件,并将文件名传递给函数参数,但是我收到错误:“系统找不到指定的文件”。有没有人对这个错误解决方案有任何想法?我的代码就像:
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;
}