java遇到过早的文件结束异常
我正试图解析现有的xhtml文件,以便将额外的正文内容添加到该文件中。我使用的代码如下:
首先,我从Jsoup中读取主体,并试图将其放入XHTML文件中
Document doc = Jsoup.parse(readFile, "UTF-8");
Elements content = doc.getElementsByTag("body");
try {
Document document=null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Create the builder and parse the file
document = (Document)factory.newDocumentBuilder().parse(finalFile);
//document.getElementsByTagName("body")append(content.toString());
//document=parserXML(finalFile);
document.getElementsByTag("body").append(content.toString());
} catch (SAXException e) {
System.out.println("SAXException>>>>>>");
e.printStackTrace();
} catch (ParserConfigurationException e) {
System.out.println("in parser configuration Exception block>>>>>>");
e.printStackTrace();
}
但我得到了以下例外:
[Fatal Error] ResultParsedFile.html:1:1: Premature end of file.
org.xml.sax.SAXParseException: Premature end of file.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at com.converter.typeconverter.EmailTypeConverter.readHTML(EmailTypeConverter.java:101)
at com.converter.typeconverter.EmailTypeConverter.callTika(EmailTypeConverter.java:64)
at com.converter.master.ApplicationMain.main(ApplicationMain.java:64)
请帮我解决这个问题
提前谢谢
# 1 楼答案
我最近经历了这个错误,结果是我的一个错误。哈佛商学院。xml文件被生成为空,错误是从引用hbm文件的应用程序上下文xml生成的