重解析xml后出错:Content is not allowed in trailing section.
Content is not allowed in trailing section. org.xml.sax.SAXParseException: Content is not allowed in trailing section. 总结一下,这个问题主要出现的原因有两点。
1、XML内容不正确,比如多个空格,换行等等。需要仔细排查; 2、使用Stream读取流文件不正确,详细如下: 读写文件时,一般采用的是每次从inputStream中read 一个有固定大小的byte array时,这时候在 byte[] array = new byte[1024]; BufferedInputStream buffInput = new BufferedInputStream(inputStream); FileOutputStream fileOS = new FileOutputStream(targetFile); BufferedOutputStream buffOS = new BufferedOutputStream(fileOS); int word = 0; while ((word = buffInput.read(array)) != -1){ buffOS.write(array); } 上面的写法,如果最后一次read到array中不足1024的时候,前一次read的byte同样会出现在byte[]中,从而导致XML解析失败。因此可以采用下面的方法: while ((word = buffInput.read()) != -1){ buffOS.write(word); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |