MalformedByteSequenceException:2 字节 UTF-8 序列的字节 2 无效 [英] MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence
问题描述
我有一个包含阿拉伯字符的 xml 文件.当我尝试解析文件时,出现异常,MalformedByteSequenceException:2 字节 UTF-8 序列的无效字节 2.我使用 POI DOM 解析文档.
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.
日志是,
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)
异常只出现在windows机器上,在Linux机器上不会出现.我该如何解决这个问题.任何建议都应该是可观的.
The exception arise only in windows Machine,not arise in Linux Machine.How can i resolve the issue.Any suggestion should be appreciable.
推荐答案
我已经解决了这个问题,通过使用 UTF8 格式创建 XML 文件.
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屋!