【发布时间】:2010-05-25 12:42:49
【问题描述】:
我的错误是:“1 字节 UTF-8 序列的字节 1 无效”。
我正在使用 Blaze DS 调用 Java 方法。
【问题讨论】:
标签: java apache-flex
我的错误是:“1 字节 UTF-8 序列的字节 1 无效”。
我正在使用 Blaze DS 调用 Java 方法。
【问题讨论】:
标签: java apache-flex
您的 XML 文档有一个 BOM 标记,因为它是使用 Windows 程序创建的。
Java 不支持此功能。
关于物料清单: 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);
【讨论】:
Hi Nithi 确保“remoting-config.xml”目标 ID 和源名称正确。
【讨论】:
问题中没有足够的细节。
我的猜测, 看起来您正在尝试读取 UTF-8 编码的内容,但它不是有效的 UTF-8 编码。
【讨论】:
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()) ;
}
}
【讨论】: