org.xml.sax.SAXParseException: Invalid byte 2 of 2-byte UTF-8 sequence。解析xml,出现该异常。
SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new File(responseXmlPath)); Element foo = doc.getRootElement();
在生成Document 对象时,Eclipse编译文件的编码或者文件所在地的编码和该文件需要的编码不一致,会产生该异常。 解决办法:在生成该文件或者向文件中写入文件时,指定为所需编码。如:
BufferedWriter bw = null; try { bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(new File(responseXmlPath)), "UTF-8")); bw.write(resultStr); bw.flush(); } catch (UnsupportedEncodingException e) { logger.error("when create OutputStreamWriter, encoding error", e); } catch (IOException e) { logger.error("when write resultStr to responseXml error:", e); } finally { if (bw != null) try { bw.close(); } catch (IOException e) { logger.error( "when finally close the BufferedWriter error:", e); } }
最好在获取Documen的时候,也用指定编码的IO获取。
Document doc = builder.build(new InputStreamReader( new FileInputStream(new File(responseXmlPath)), "UTF-8"));
但是生成文件时,必须指定为所需编码。
相关推荐
NULL 博文链接:https://wilian.iteye.com/blog/1992365
错误提示Invalid byte 1 of 1-byte UTF-8 sequence原因分析在中文版的window下java的默认的编码为GBK,也就是所虽然我们标识了要将xml保存为utf-8格式但实际上文件是以GBK格式来保存的,所以这也就是为什么能够我们...
org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'area'. One of '{MathWorksID, type}' is expected. 运行hosaver: Warning: Could not find an exact ...
javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing '- WSDL Document -'.: org.xml.sax.SAXParseException: The element type "p" must be terminated by the matching end-tag ...
org.xml.sax.SAXParseException: PI must not start with xml (position:unknown xm@3:5 in java.io.InputStreamReader@43e4b480) 经过多次查找确认XML语法没错误。 问题原因: 为XML文件第一行格式错误,仔细修改第
BeRoot, 特权升级项目 Windows/Linux/Mac BeRoot项目BeRoot项目是一个发布工具,用于检查常见的以找到一种方法来升级我们的特权。它已经被添加到 pupy 项目作为一个post开发模块( 所以它将在内存中执行而不需要触摸...
好多版本是会报错的,[Fatal Error] :24:28: An ... org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xd863) was found in the element content of the documen.,这个版本是纠正过后重新打包做的
好多版本是会报错的,[Fatal Error] :24:28: An ... org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xd863) was found in the element content of the documen.,这个版本是纠正过后重新打包做的
解决启动dubbo项目的时候出现,无法读取方案文档 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd',其实在你本地把dubbo.jar文件解压,然后在META-INF下边就有个dubbo.xsd,就是他
Chapter 8: XSL Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 Chapter 9: XSL Formatting Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Part II: Microsoft ...
sax2 SAX的工作原理简单地说就是对文档进行顺序扫描,当扫描到文档(document)开始与结束、元素(element)开始与结束、文档(document)结束等地方时通知事件处理函数,由事件处理函数做相应动作,然后继续同样的...
SAX.java 操作xml文件SAX.java 操作xml文件SAX.java 操作xml文件SAX.java 操作xml文件SAX.java 操作xml文件SAX.java 操作xml文件SAX.java 操作xml文件SAX.java 操作xml文件
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd', because 1) could not find the document; 2) the document could ...
Cause: org.xml.sax.SAXParseException; lineNumber: 99; columnNumber: 17; 元素类型为 “configuration” 的内容必须匹配 “(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWra
android调用xmlrpc的方法会出现错误 javax.xml.parsers.ParserConfigurationException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities。 本文通过自己的方法来...
JavaTM 2 Platform Standard Ed. 5.0 所有类 软件包 java.applet java.awt java.awt.color java.awt.datatransfer java.awt.dnd java.awt.event ...javax.xml javax.xml.datatype ...org.xml.sax.helpers
离线安装包,亲测可用
解析XML所需的jar sax.jar
Java解析XML的三种方式 ...Ø 2、SAX(org.xml.sax) Ø SimpleAPI for XML,以事件的形式通知程序,对Xml进行解析。 Ø 3、XMLPULL(org.xmlpull.v1) Ø 类似于SAX方式,程序以“拉取”的方式对Xml进行解析。
javax.xml.transform.sax 此包实现特定于 SAX2 的转换 API。 javax.xml.transform.stax 提供特定于 StAX 的转换 API。 javax.xml.transform.stream 此包实现特定于流和 URI 的转换 API。 javax.xml.validation 此...