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

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

    I had this problem, but the file was in UTF-8, it was just that somehow on character had come in that was not encoded in UTF-8. To solve the problem I did what is stated in this thread, i.e. I validated the file: How to check whether a file is valid UTF-8?

    Basically you run the command:

    $ iconv -f UTF-8 your_file -o /dev/null

    And if there is something that is not encoded in UTF-8 it will give you the line and row numbers so that you can find it.

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

    How to fix this issue ?

    Read the data using the correct character encoding. The error message means that you are trying to read the data as UTF-8 (either deliberately or because that is the default encoding for an XML file that does not specify <?xml version="1.0" encoding="somethingelse"?>) but it is actually in a different encoding such as ISO-8859-1 or Windows-1252.

    To be able to advise on how you should do this I'd have to see the code you're currently using to read the XML.

    0 讨论(0)
  • 2020-11-28 14:51
    This error comes when you are trying to load jasper report file with the extension .jasper
    For Example 
    c://reports//EmployeeReport.jasper"
    
    While you should load jasper report file with the extension .jrxml
    For Example 
    c://reports//EmployeeReport.jrxml"
    [See Problem Screenshot ][1] [1]: https://i.stack.imgur.com/D5SzR.png
    [See Solution Screenshot][2] [2]: https://i.stack.imgur.com/VeQb9.png
    
      
      
    
    0 讨论(0)
  • 2020-11-28 14:52

    Try:

    InputStream inputStream= // Your InputStream from your database.
    Reader reader = new InputStreamReader(inputStream,"UTF-8");
    
    InputSource is = new InputSource(reader);
    is.setEncoding("UTF-8");
    
    saxParser.parse(is, handler);
    

    If it's anything else than UTF-8, just change the encoding part for the good one.

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

    I have met the same problem and after long investigation of my XML file I found the problem: there was few unescaped characters like « ».

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

    I happened to run into this problem because of an Ant build.

    That Ant build took files and applied filterchain expandproperties to it. During this file filtering, my Windows machine's implicit default non-UTF-8 character encoding was used to generate the filtered files - therefore characters outside of its character set could not be mapped correctly.

    One solution was to provide Ant with an explicit environment variable for UTF-8. In Cygwin, before launching Ant: export ANT_OPTS="-Dfile.encoding=UTF-8".

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