转自网上:
An invalid XML character (Unicode: 0x4) was found in the element content of the document.
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x4) was found in the element content of the document.
原因是在获取InputStream的时候,使用了StringBufferInputStream(String
source)方法,这个方法在将String构造成InputStream的时候会破坏String原来的字符编码。比如你使用的是gb2312,但是
它按照系统默认的编码比如iso-8259-1或者Unicode-16之类来解析,那就会出现字符转换错误。这里面可能就刚好有一个被错误的转换成了
Unicode:0x4, 所以就报了上面的错。解决的方法是:
1 - 在转换的时候声明字符编码,或者进行一下转换(未尝试,不知道是否可行)
2 - 使用ByteArrayInputStream来替代StringBufferInputStream。