How to fix Invalid byte 1 of 1-byte UTF-8 sequence

后端 未结 13 1284
我寻月下人不归
我寻月下人不归 2020-11-28 13:54

I am trying to fetch the below xml from db using a java method but I am getting an error

Code used to parse the xml

DocumentBuilderFactory dbf = Docu         


        
相关标签:
13条回答
  • 2020-11-28 14:58

    I had a similar problem. I had saved some xml in a file and when reading it into a DOM document, it failed due to special character. Then I used the following code to fix it:

    String enco = new String(Files.readAllBytes(Paths.get(listPayloadPath+"/Payload.xml")), StandardCharsets.UTF_8);
    
    Document doc = builder.parse(new ByteArrayInputStream(enco.getBytes(StandardCharsets.UTF_8)));
    

    Let me know if it works for you.

    0 讨论(0)
提交回复
热议问题