MalformedByteSequenceException:2字节UTF-8序列的无效字节2 [英] MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence

查看:3594
本文介绍了MalformedByteSequenceException:2字节UTF-8序列的无效字节2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含阿拉伯语characters.When我尝试解析文件的XML文件,它出现异常,MalformedByteSequenceException:无效字节2个字节的UTF-8使用sequence.I POI为DOM解析文档<。 / p>

日志是,

  2012-03-19 11:30:00433 [错误](com.infomindz.remitglobe.bll.remittance.BlackListBean) - 错误com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:2字节的UTF-8序列的无效字节2。    在com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(来源不明)    在com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(来源不明)    在com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(来源不明)    在com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(来源不明)    在com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown资源)    在com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(来源不明)    在com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(来源不明)    在com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(来源不明)    在com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(来源不明)    在com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(来源不明)    在com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(来源不明)    在com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(来源不明)    在javax.xml.parsers.DocumentBuilder.parse(来源不明)    在com.infomindz.remitglobe.bll.remittance.BlackListBean.updateGeneralBlackListDetail(来源不明)    在com.infomindz.remitglobe.bll.remittance.schedulers.BlackListUpdateScheduler.executeInternal(来源不明)    在org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)    在org.quartz.core.JobRunShell.run(JobRunShell.java:216)    在org.quartz.simpl.SimpleThreadPool $ WorkerThread.run(SimpleThreadPool.java:549)

例外才会出现在Windows机器上,无法在Linux中Machine.How出现,我可以解决issue.Any建议应该AP preciable。


解决方案

我有解决这个问题,通过使用UTF8格式创建XML文件。

  OutputStreamWriter的BufferedWriter =新OutputStreamWriter(文件路径+
                        System.getProperty(文件分割符)+文件名),UTF8);

创建使用上述code中的文件后,编码问题对于每一位resolved.Thanks,就把精力在这里。

I have a xml file which contains arabic characters.When i try to parse a file,it arise the Exception,MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence.I Use POI DOM for parse the document.

The Log is,

2012-03-19 11:30:00,433 [ERROR] (com.infomindz.remitglobe.bll.remittance.BlackListBean) - Error 

com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 2-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.skipChar(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.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.DOMParser.parse(Unknown Source)

    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)

    at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)

    at com.infomindz.remitglobe.bll.remittance.BlackListBean.updateGeneralBlackListDetail(Unknown Source)

    at com.infomindz.remitglobe.bll.remittance.schedulers.BlackListUpdateScheduler.executeInternal(Unknown Source)

    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)

    at org.quartz.core.JobRunShell.run(JobRunShell.java:216)

    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)

The exception arise only in windows Machine,not arise in Linux Machine.How can i resolve the issue.Any suggestion should be appreciable.

解决方案

I have resolve the problem,by create the XML file using UTF8 format.

OutputStreamWriter bufferedWriter = new OutputStreamWriter(filePath +
                        System.getProperty("file.separator") + fileName), "UTF8");

After create the file using the above code,the encoding problem is resolved.Thanks for every one,put the effort here.

这篇关于MalformedByteSequenceException:2字节UTF-8序列的无效字节2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆