开发者

Getting Premature end of file Exception

开发者 https://www.devze.com 2023-04-04 15:40 出处:网络
I\'m trying to parse the existing xhtml file to add the additional body content into that file. I am using the following code:

I'm trying to parse the existing xhtml file to add the additional body content into that file. I am using the following code:

First I am reading the body from the Js开发者_运维百科oup and i am trying to put it in the XhtmlFile

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();
            }

But i am getting the following exception:

[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)

Plese help me in solving this issue ...

Thanks in advance...


If you get this error at the first position of the file (which the 1:1 indicates) it means that the file is empty.

Maybe you start reading the file before the source has closed it?

In case you use an input stream (which is not the case here), this can happen when you re-use a stream that you have already used to reach the end of the file. You need to create a new stream from the input file in order to reset it from the start of the file.


The message indicates that you have a badly formed XML file. Usually when I've gotten this message I had an opening tag with no matching end tag. I think you'll also get this on an empty file.


I had recently experienced this error, turns out one of my .hbm.xml files was being generated as empty, error was being generated from application context xml which was referring to the hbm file


1.xml is not readable. 2.To rectify the xml ,only option is to drag and drop into spreadsheet,error will be highlighted more clear.after doing suggested correction xml will finally be loaded to spreadsheet.then that xml which is successfully loaded will not face any parsing issue

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号