DocumentBuilder parse produces invalid byte 2 of 4

2019-07-14 04:25发布

I am trying to parse a bytearray which contains a string Impresión in XML

final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = builderFactory.newDocumentBuilder();
final Document document;
try (final InputStream stream = new ByteArrayInputStream(bytearray)) {
     document = builder.parse(stream); // gives Invalid byte 2 of 4-byte UTF-8 sequence error
}

It produces Invalid byte 2 of 4-byte UTF-8 sequence error. But when i have Unicode Impresi\u00f3n, it works fine. But i want to parse actual character.

Anybody help me to solve it.

0条回答
登录 后发表回答