[英]“Invalid byte 1 of 1-byte UTF-8 sequence” error
我的错误是:“ 1字节UTF-8序列的无效字节1”。
我正在使用Blaze DS调用Java方法。
您的XML文档具有BOM标记,因为它是使用Windows程序创建的。
Java不支持此功能。
关于BOM: http : //www.unicode.org/faq/utf_bom.html
因此,请确保您的XML文档没有BOM标记(如果它是您的ds配置文件),或者在InputStream中使用类似以下内容的代码:
(不是我的代码) 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);
问题中没有足够的细节。
我的猜测是,您似乎正在尝试读取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.