简体   繁体   English

“ 1字节UTF-8序列的无效字节1”错误

[英]“Invalid byte 1 of 1-byte UTF-8 sequence” error

My error is: "Invalid byte 1 of 1-byte UTF-8 sequence". 我的错误是:“ 1字节UTF-8序列的无效字节1”。

I am calling a Java method using Blaze DS. 我正在使用Blaze DS调用Java方法。

Your XML document has a BOM marker, because it was created with a Windows program. 您的XML文档具有BOM标记,因为它是使用Windows程序创建的。

Java does not support this out of the box. Java不支持此功能。

Regarding BOM: http://www.unicode.org/faq/utf_bom.html 关于BOM: http//www.unicode.org/faq/utf_bom.html

So either make sure your XML Document has no BOM marker, (if it is your ds config file), or use something like this in your InputStream: 因此,请确保您的XML文档没有BOM标记(如果它是您的ds配置文件),或者在InputStream中使用类似以下内容的代码:

(not my code) http://koti.mbnet.fi/akini/java/unicodereader/UnicodeInputStream.java.txt (不是我的代码) http://koti.mbnet.fi/akini/java/unicodereader/UnicodeInputStream.java.txt

Usage pattern:
 String enc = "ISO-8859-1"; // or NULL to use systemdefault
 FileInputStream fis = new FileInputStream(file);
 UnicodeInputStream uin = new UnicodeInputStream(fis, enc);
 enc = uin.getEncoding(); // check and skip possible BOM bytes
 InputStreamReader in;
 if (enc == null) in = new InputStreamReader(uin);
 else in = new InputStreamReader(uin, enc);

not enough details in the question. 问题中没有足够的细节。

my guess, looks like you are trying to read something as UTF-8 encoded and it is not valid UTF-8 encoded. 我的猜测是,您似乎正在尝试读取UTF-8编码的内容,但它不是有效的UTF-8编码。

您好Nithi,请确保“ remoting-config.xml”目标ID和源名称正确。

ByteArrayInputStream test = new ByteArrayInputStream( xml.trim().getBytes() );
Document document = null;
try {
    document = dbf.newDocumentBuilder().parse( test );
} catch ( Exception e ) {
    System.out.println( "Fehler 1" + e.getMessage()) ;
    try {
        test.close();
        // ... that works: String xml_x = FkString.replace( xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" );
        // Replace UTF-8 to UTF8 ... works
        String xml_x = FkString.replace( xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<?xml version=\"1.0\" encoding=\"UTF8\"?>" );
        test = new ByteArrayInputStream( xml_x.trim().getBytes() );
        document = dbf.newDocumentBuilder().parse( test );
    } catch ( Exception e1 ) {
        System.out.println( "Fehler 2" + e1.getMessage()) ;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JAXB错误的说明:1字节UTF-8序列的字节1无效 - Explanation of JAXB error: Invalid byte 1 of 1-byte UTF-8 sequence MalformedByteSequenceException:1字节UTF-8序列的无效字节1 - MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence 消息:hadoop中1字节UTF-8序列的无效字节1 - Message: Invalid byte 1 of 1-byte UTF-8 sequence in hadoop 如何修复 1 字节 UTF-8 序列的无效字节 1 - How to fix Invalid byte 1 of 1-byte UTF-8 sequence MalformedByteSequenceException 1 字节 UTF-8 序列的字节 1 无效 - MalformedByteSequenceException Invalid byte 1 of 1-byte UTF-8 sequence JRException:1字节UTF-8序列的无效字节1 - JRException: Invalid byte 1 of 1-byte UTF-8 sequence getResponseBodyAsStream返回“ 1字节UTF-8序列的无效字节1” - getResponseBodyAsStream returns “Invalid byte 1 of 1-byte UTF-8 sequence” 将XMI文件导入XML项目错误:1字节utf-8序列的无效字节1 - Import an XMI file to a XML project Error : Invalid byte 1 of 1-byte utf-8 sequence 我有UTF-8-但仍然收到“ 1字节UTF-8序列的无效字节1” - I have UTF-8 - but still get “Invalid byte 1 of 1-byte UTF-8 sequence” 如何删除XML中的特殊字符,并且在读取此xml文件时不应导致错误“1字节UTF-8序列的无效字节1” - How to remove the special characters in XML and should not lead to the error “Invalid byte 1 of 1-byte UTF-8 sequence” while reading this xml file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM