解决解析xml报UTFDataFormatException方案

解析XML报错:

UTFDataFormatException: invalid byte 2 of 2-byte UTF-8 sequence (0xfa)

解决方案:

SAXReader reader = new SAXReader();
org.dom4j.Document document = reader.read(new ByteArrayInputStream(s.getBytes());

改成:

SAXReader reader = new SAXReader();
org.dom4j.Document document = reader.read(new ByteArrayInputStream(s.getBytes("UTF-8")));

你可能感兴趣的:(JAVA基础)