java - When reading a file, the console reports the following error, please solve it! ! !
習慣沉默
習慣沉默 2017-07-03 11:43:26
0
4
946

1. As shown below: The console error message is as follows:


2. The background code is:


3.xml file is as follows:


Please ask God to solve it. Urgent, wait online. Many methods on Baidu don’t work. Please ask God to solve it! !

習慣沉默
習慣沉默

reply all(4)
伊谢尔伦

I tried it with your code and no errors occurred. If there is an error with dom4j, try something else

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
ClassPathResource resource = new ClassPathResource("reportType.xml");
Document doc = builder.parse(resource.getInputStream());
Element root = doc.getDocumentElement();
NodeList list = root.getChildNodes();
for (int i = 0, len = list.getLength(); i < len; i++) {

Node node = list.item(i);

}

过去多啦不再A梦

I think it’s a problem with your xml file. The error translated is: The file ended early! The xml file may have no end tag, wrong start tag, etc. You may encounter this error! Please post your complete xml file

某草草
Problem: Input stream is opened and read bytes from it, passed the same to document builder to parse method. so it caused the exception saying premature end of file.
Solution: Pass fresh input stream which is opened and not read anything (bytes) before passing to parse method of DocumentBuilder object.
伊谢尔伦

Encoding problem? Try changing the xml file attributes to UTF-8

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template