`
623deyingxiong
  • 浏览: 188902 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

MalformedByteSequenceException: Invalid byte 2 of 3-byte UTF-8 sequence

阅读更多

代码行:

String content=new String(getBytesFromFile(new File("monitor_config.xml")));
		Document doc = null;
		SAXBuilder saxBuilder = new SAXBuilder();
		
		try {
			doc = saxBuilder.build(new ByteArrayInputStream(content.getBytes()));
		} catch (JDOMException e) {
			throw new SettingsException("monitor配置读取时出现xml解析异常", e);
		} catch (IOException e2) {
			throw new SettingsException("monitor配置读取时出现I/O异常", e2);
		}

 

stack trace:

Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 3-byte UTF-8 sequence.
 at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanLiteral(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanAttributeValue(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanAttribute(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
 at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
 at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
 at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
 at org.jdom.input.SAXBuilder.build(SAXBuilder.java:770)
 at com.metarnet.adapter.ecm.monitor.setting.impl.MonitorSettings.read(MonitorSettings.java:46)
 ... 5 more

 

解决方法:首先确定要读取文件的编码格式为UTF-8,

                然后将

saxBuilder.build(new ByteArrayInputStream(content.getBytes()));

 改为:

                 

  saxBuilder.build(new ByteArrayInputStream(content.getBytes("UTF-8")));

 

分享到:
评论

相关推荐

    解决Invalid byte 1 of 1-byte UTF-8 sequence

    解决Invalid byte 1 of 1-byte UTF-8 sequence

    php解析xml提示Invalid byte 1 of 1-byte UTF-8 sequence错误的处理方法

    在利用php解析xml时提示Invalid byte 1 of 1-byte UTF-8 sequence错误了,这个问题我百度查实说是编码问题,结果我把编码处理一下果然KO了,下面我来分享一下解决办法

    SQL Server数据迁移至PostgreSQL出错的解释以及解决方案

    最近对SQL Server到PostgreSQL的数据迁移时出现了问题,返回的错误为:invalid byte sequence for encoding "UTF8": 0x00。经查证pg源代码,该问题引起的原因是sql server的字符类型字段中含有空字符0,该字符在pg中...

    ruby中文文档(ruby入门级别教程)

    包括ruby用户指南,RGSS入门教程,Programming Ruby,Ruby参考手册共4部分内容。 chm格式

    android layout XML解析错误的解决方法

    org.xml.sax.SAXParseException: PI must not start with xml (position:unknown xm@3:5 in java.io.InputStreamReader@43e4b480) 经过多次查找确认XML语法没错误。 问题原因: 为XML文件第一行格式错误,仔细修改第

    Chatlog_Ripper:一个帮助你从聊天记录文件中提取 URL 的小程序

    聊天记录开膛手在 WDI 中,我们共享一切。... 如果您收到错误“in `scan': invalid byte sequence in UTF-8 (ArgumentError)”,只需将您的文本日志解析为可以转换为 UTF-8 的内容(例如 )。 我将来会解决这个问题。

    pyquery报错:UnicodeDecodeError: ‘gbk’ codec can’t decode byte

    今天想使用pyquery库读取本地HTML文件时报错:UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa1 in position 164: illegal multibyte sequence。 翻译一下就是UnicodeDecodeError: ‘gbk’编解码器无法...

    LuaUnicode icu-lua

    by-octet string comparison of an octet sequence would produce the same result if a naive octet-by-octet string comparison were done on the UTF-8 encoding of the octet sequence. This is also true of ...

    S7A驱动720版本

    polling, after CP5611 sent a specific sequence of communication errors. Build 219 : Solved problems: Improvements and new functions: - New Parameter "Max Gap (Bytes)" on Setup parameter property...

    k7 SRIO参考例程

    byte-wise writes of CSRs such as the deviceID register and BAR. - Message response transaction received as a user defined packet type using 16-bit device IDs appears as a corrupted packet on the ...

    eac3to V3.17

    * added support for MKV "SRT/UTF8", "SRT/ASCII", "ASS" and "SSA" subtitles * increased some internal buffers to avoid AC3 overflow in the "thd ac3 joiner" * fixed: frame counting didn't work for MKV ...

    Bochs - The cross platform IA-32 (x86) emulator

    In order to enable emulation of VMXx2 extensions configure with --enable-vmx=2 option (x86-64 must be enabled) - Bugfixes for CPU emulation correctness - Fixed Bochs crash when accessing the first...

    acpi控制笔记本风扇转速

    Debug Version: 155.2K Code, 63.1K Data, 218.3K Total 2) iASL Compiler/Disassembler and Tools: Fixed a problem where the presence of the _OSI predefined control method within complex expressions ...

    iuhyiuhkjh908u0980

    在windows系统中,命令行中执行ant命令时,当指定的 构建脚本文件中包含中文字符,而构建脚本文件的编码是UTF-8时将会 Invalid byte 1 of 1-byte UTF-8 sequence. 的错误.这个问题尚未 知解决,故先采用GBK的编码. 2.在...

    微软内部资料-SQL性能优化3

    Byte 2-3: DBID – 0x0005 Byte 4-7: ObjectID – 0x 75D7831F (1977058079) Byte 8-9: IndexID – 0x0001 Byte 10-16: Hash Key value – 0x 02014F0BEC4E For more information about how to decode this ...

    The Art of Assembly Language Programming

    3 Organization of This Text and Pedagogical Concerns 4 Obtaining Program Source Listings and Other Materials in This Text <br>Section One: Machine Organization <br>Art of Assembly ...

    CE中文版-启点CE过NP中文.exe

    Fixed freeze with allow increase/decrease for 8 byte long values Fixed several issues where minimizing a window and then close it would hang CE Fixed file scanning Fixed crashes when editing memory in...

    doctest:Haskell的python doctest的实现

    Doctest:测试交互式Haskell示例doctest是一个小程序,用于检查。 它与相似,。安装可以从获得doctest 。 通过键入以下内容进行安装: cabal install doctest确保Cabal的bindir在您的PATH 。 在Linux上: export ...

Global site tag (gtag.js) - Google Analytics