Premature end of file 错误解决 (2011-01-21 10:02:22)
来源:互联网 发布:淘宝宝贝标题是什么 编辑:程序博客网 时间:2024/06/06 07:33
Premature end of file 错误解决
(2011-01-21 10:02:22)输入流
解析
premature
xml
dom4j
杂谈
分类: 工作相关最近在做一个打印的工作,需要对输入流的xml信息进行解析。为了能够满足多元化的需求,这个输入流需要解析多次,使用同一个方法进行解析,在第二次的时候就会抛出一个异常,解析后的document对象也为null。
[Fatal Error] :-1:-1: Premature end of file.
org.xml.sax.SAXParseException: Premature end of file.
百思不得其解,昨日想了一个应对方法,将输入流先读取到一个byte[]对象中,在第二次解析的时候,使用这个byte[]来解决。结果问题更加郁闷,在第一次调用解析的时候,就报错了。欲哭无泪啊……
任务就是任务,不管你有多少困难都要迎头赶上,继续埋头苦思问题的所在。还好如今互联网发达了,可以让我找到问题的源头。参考文献如下:
使用dom4j解析来自InputStream中的XML内容,发生异常:Premature end of file。是因为这个InputStream已经读过了,在读入dom4j时,不是从开头读的,因此报错。
详细解释如下:来自http://forums.sun.com/thread.jspa?threadID=641465。非常遗憾,sun被oracle收购了,所以这个地址不存在了……
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.
还别说,我之前想到的那个先读入byte[]的想法还是比较好的,只要后续的操作使用new ByteArrayInputStream(tbyte),就没有再出现解析的问题。
- Premature end of file 错误解决 (2011-01-21 10:02:22)
- Premature end of file 错误解决
- premature end of file错误
- dom4j解决Premature end of file
- 解决SAXParseException: Premature end of file
- Premature end of file
- Premature end of file
- SAXParseException : Premature end of file
- DOM4J:Premature end of file
- Premature end of JPEG file
- xml中的Premature end of file
- Error on line -1 of document : Premature end of file. Nested exception: Premature end of file.
- 解决Premature end of script headers
- 2017-08-22-dom4j启动报错Premature end of file.
- 16-01-14 EditText 设置圆角 及 Premature end of file 解决方法
- premature end of file web service之类的问题解决
- 编译Android程序时,遇到premature end of file问题
- [Fatal Error] :-1:-1: Premature end of file.
- 关于优先级队列STL
- Python,Django安装MySQLdb各种经典错误(Error No module named MySQLdb)
- 为什么printf("%f\n",5)输出0.000000
- 使用supervisord来管理process
- UVA 10192 Vacation LCS
- Premature end of file 错误解决 (2011-01-21 10:02:22)
- Xcode 4.3中在iOS上应用Static Library及Static Framework笔记
- ALGOL
- FTP SFTP SCP OpenSSL SSH
- POJ 1691 Painting A Board
- Linux命令:top
- 个人关于管理一些中型程序的见解
- oracle11g安装时报INFO:INFO错误解决
- Linux命令:scp