我试图从字节解析文档如下无效字节2 4字节文档解析
String result = /* some valid xml document */
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
try {
Document document = parser.parse(new ByteArrayInputStream(result.getBytes()));
} catch (MalformedByteSequenceException e) {
System.out.println("(MalformedByteSequenceException) " + e.getMessage());
}
甲MalformedByteSequenceException被抛出并且下一个被打印在控制台中UTF-8序列
"(MalformedByteSequenceException) Invalid byte 2 of 4-byte UTF-8 sequence."
奇怪的是,同样的代码在我的本地环境(Windows 10),但不是在远程环境(Windows Server 2012中)
我试图复制ERR或者在我的本地环境中将TomEE版本从1.7.4更改为1.7.1,我尝试将JRE从1.7.0_80更改为1.7.0,我尝试将远程系统中的完整Tomee文件夹复制到本地机器,错误只发生在远程环境中
使用result.getBytes(Charset.forName("UTF-8"))
而不是result.getBytes()
也没有工作。
您的Unicode文件在序言中是否有编码? – bmargulies
xml文件来自web服务响应,而不是来自文件 –
同样的问题。有没有编码=? – bmargulies