`

xml 文件提前结束 or 前言中不允许有内容

阅读更多
控制台提示信息:
1.


2.


在解析 xml格式的 InputStream,要先转字节码处理下再解析,否则可能会出现上面的错误。

public static String InputStreamTOString(InputStream in,String encoding) throws Exception{  
        
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();  
        byte[] data = new byte[4096];  
        int count = -1;  
        while((count = in.read(data,0,2048)) != -1)  
            outStream.write(data, 0, count);  
          
        data = null;  
        return new String(outStream.toByteArray(),"ISO-8859-1");  
    }


==========================================================================

String xmlStr = this.InputStreamTOString(is, "utf-8");
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.parse(new InputSource(new StringReader(xmlStr)));

  • 大小: 98.9 KB
  • 大小: 396.3 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics