这是代码:
public Document getFile(String path) throws ParserConfigurationException, SAXException, IOException{
String classpath = FileInputUtil.class.getClassLoader().getResource("").getPath();
String parentpath = classpath.substring(0,classpath.lastIndexOf("classes"))+"date/";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(parentpath+path);
return doc;
}
public static void main(String[] args) throws Exception{
FileInputUtil fiu = new FileInputUtil();
Document doc = fiu.getFile("aboutUs.xml");
System.out.println(doc);
}
这是结果:
[#document: null]
请问一下怎么会是null,我打印过db.parse(parentpath+path),也是null,该文件的确存在,里面也有内容
public Document getFile(String path) throws ParserConfigurationException, SAXException, IOException{
String classpath = FileInputUtil.class.getClassLoader().getResource("").getPath();
String parentpath = classpath.substring(0,classpath.lastIndexOf("classes"))+"date/";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(parentpath+path);
return doc;
}
public static void main(String[] args) throws Exception{
FileInputUtil fiu = new FileInputUtil();
Document doc = fiu.getFile("aboutUs.xml");
System.out.println(doc);
}
这是结果:
[#document: null]
请问一下怎么会是null,我打印过db.parse(parentpath+path),也是null,该文件的确存在,里面也有内容