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

后端 未结 13 1283
我寻月下人不归
我寻月下人不归 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:38

    Those like me who understand character encoding principles, also read Joel's article which is funny as it contains wrong characters anyway and still can't figure out what the heck (spoiler alert, I'm Mac user) then your solution can be as simple as removing your local repo and clone it again.

    My code base did not change since the last time it was running OK so it made no sense to have UTF errors given the fact that our build system never complained about it....till I remembered that I accidentally unplugged my computer few days ago with IntelliJ Idea and the whole thing running (Java/Tomcat/Hibernate)

    My Mac did a brilliant job as pretending nothing happened and I carried on business as usual but the underlying file system was left corrupted somehow. Wasted the whole day trying to figure this one out. I hope it helps somebody.

    0 讨论(0)
  • 2020-11-28 14:39
    1. Open the xml in notepad
    2. Make sure you dont have extra space at the beginning and end of the document.
    3. Select File -> Save As
    4. select save as type -> All files
    5. Enter file name as abcd.xml
    6. select Encoding - UTF-8 -> Click Save
    0 讨论(0)
  • 2020-11-28 14:41

    I was getting the xml as a String and using xml.getBytes() and getting this error. Changing to xml.getBytes(Charset.forName("UTF-8")) worked for me.

    0 讨论(0)
  • 2020-11-28 14:42

    I had the same issue. My problem was it was missing “-Dfile.encoding=UTF8” argument under the JAVA_OPTION in statWeblogic.cmd file in WebLogic server.

    0 讨论(0)
  • 2020-11-28 14:47

    I had the same problem in my JSF application which was having a comment line containing some special characters in the XMHTL page. When I compared the previous version in my eclipse it had a comment,

    //Some �  special characters found
    

    Removed those characters and the page loaded fine. Mostly it is related to XML files, so please compare it with the working version.

    0 讨论(0)
  • 2020-11-28 14:47

    You have a library that needs to be erased Like the following library

       implementation 'org.apache.maven.plugins:maven-surefire-plugin:2.4.3'
    
    0 讨论(0)
提交回复
热议问题