使用dom4j解析来自InputStream中的XML内容,发生异常:Premature end of file
原来是这个InputStream已经读过了,在读入dom4j时,不是从开头读的,因此报错。
详细解释如下:来自http://forums.sun.com/thread.jspa?threadID=641465
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.