我正在使用 Hadoop 解析 XML,并且我从 here 获得了代码.
但我收到以下错误:
FINISH_TIME="1385387129970" HOSTNAME="DEV140" ERROR="java.io.IOException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[18,3] Message: Invalid byte 1 of 1-byte UTF-8 sequence.
但我的 XML 仅使用 UTF-8 编码。那我该如何处理呢?
最佳答案
我怀疑这就是问题所在 - 这至少是一个问题:
XMLStreamReader reader =
XMLInputFactory.newInstance().createXMLStreamReader(new
ByteArrayInputStream(document.getBytes()));
对 getBytes 的调用将使用平台默认编码,而不是 UTF-8。
您可以将“utf-8”指定为编码名称——但创建一个StringReader会更简单:
XMLStreamReader reader = XMLInputFactory.newInstance()
.createXMLStreamReader(new StringReader(document));
当然,这可能不是唯一的错误,但至少值得关注。
关于java - 消息 : Invalid byte 1 of 1-byte UTF-8 sequence in hadoop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20194876/